Skip to main content
Known Participant
April 21, 2014
Question

How can I update a table from a query without using form?

  • April 21, 2014
  • 2 replies
  • 595 views

i want to be able to update a table cse_montly_reports

this is my code right now

<cfquery datasource="Intranet" name="reports">

  with Employee_cte as (

      Select e.*,

             (Select SUM(r.execoffice_status)

              From intranet.dbo.CSEReduxResponses r

              where e.emp_id = r.employee

              and YEAR(r.approveddate) = YEAR(GETDATE())

                and    MONTH(r.approveddate) = MONTH(GETDATE())-1

                    and execoffice_status <> 2

             ) as TotalStars

     From phonelist.dbo.employee e

    )

Select Top 10 RANK() Over (Order by TotalStars DESC) AS EmployeeRank,*

From Employee_cte

order by TotalStars desc;

</cfquery>

<cfloop query="reports">

<cfset v_name = reports.emp_namefirst>

<cfset v_total_stars=reports.TotalStars>

<cfquery datasource="Intranet" name="inserdata">

insert into intranet.dbo.cse_monthly_reports

(

starburst_winner

starburst_winner_stars

)

values(

#v_name#

#v_total_stars#

)

</cfquery>

</cloop>

the query works and gets data for me , i have try it on my sql server.

the code above is not inserting into the cse_montly _reports table and is also not giving me any errors, is there a better way to insert into the table

the output from the query looks like something like this(doesnt show all)( and yes i know i can make this query better, but right now im more interested in insert into the other table. what im i doing wrong?

    This topic has been closed for replies.

    2 replies

    Inspiring
    April 21, 2014

    Try putting a CFDUMP after the first CFQUERY, to be sure that the query is returning any data when executed in CF.

    -reed

    Known Participant
    April 21, 2014

    @reedpowell

    just check and is returning data

    Dave Ferguson
    Participating Frequently
    April 21, 2014

    The amount of things wrong this with this is staggering.  However, I am not inclined to give you any assistance right now.  Others may but I wont.  Your lack of response to any other posts you have made in the past and lack of etiquette is getting out of hand compaired to the amount of help people have tried to tive you.

    Known Participant
    April 21, 2014

    @fergusondfj

    thank you for your input , the reason i did it this way was because of a post i saw online that did it this way (not from this forum) , so  i thought it would be correct from the input i got from the post

    Known Participant
    April 21, 2014

    after i have done some changes now it inserts into the table but returning the data twice, not sure why.

    <!--  <cfdump var="#reports#">   -->

    <cfloop query=reports>

    <cfquery name="second" datasource="Intranet">

    insert into intranet.dbo.CSE_Monthly_Reports (starburst_winner)

    values ('#emp_namefirst#')

    </cfquery>

    </cfloop>

    this is a test im doing to make sure it works