mahpog
asked on
Using a cfquery output field listing to drive a loop one at a time to generate a final output table.
I have a full listing of employee ids after performing a cfquery to output it to psidlist.psid.
I want to run the next sql query looping through the psidlist.psid one at a time, and not one whole group.
I then want to output for each employee as a summarization.
my sql query will work as long as I do one employee from the cfquery output listing, one at a time, otherwise I will err out due to scalar issues.
Question: I know there is a technique using coldfusion to go through the cfquery output listing one at a time, process the one, output the one and then go to the next one.
I need assistance. I do not remember the techinque. It has been awhile.
If I use your solution, I give full credit.
************************** ********** ********** ********** ********** ********** ********** ********** ********** ********** *****
( I will replace all psid with #psidlist.psid#)
<cfquery name="psidlist" Datasource="#Request.datas ource#">
select psid
from a_rollup_dept
order by psid
</cfquery>
<cfquery name="qdirect" Datasource="#Request.datas ource#">
select
(select psid,
from a_rollup_labor
group by "#psidlist.psid#"),
(select sum(labor_hours) from a_rollup_labor
where labor_date = '01/01/2007'
group by psid) jan_salary,
(select sum(labor_hours) from a_rollup_labor
where d_i IN ('D','I')
and proj_def in ('##')
and activity_type like 'D%'
and rcc NOT in ('80507')
group by psid) ototal,
(select sum(labor_hours) from a_rollup_labor
where labor_date = '02/01/2007'
group by psid) feb_salary,
(select sum(labor_hours) from a_rollup_labor
where labor_date = '03/01/2007'
group by psid) mar_salary,
(select sum(labor_hours) from a_rollup_labor
where labor_date = '04/01/2007'
group by psid) apr_salary,
(select sum(labor_hours) from a_rollup_labor
where labor_date = '05/01/2007'
group by psid) may_salary,
(select sum(labor_hours) from a_rollup_labor
where labor_date = '06/01/2007'
group by psid) jun_salary
</cfquery>
<cfdump var="#qDirect#">
I want to run the next sql query looping through the psidlist.psid one at a time, and not one whole group.
I then want to output for each employee as a summarization.
my sql query will work as long as I do one employee from the cfquery output listing, one at a time, otherwise I will err out due to scalar issues.
Question: I know there is a technique using coldfusion to go through the cfquery output listing one at a time, process the one, output the one and then go to the next one.
I need assistance. I do not remember the techinque. It has been awhile.
If I use your solution, I give full credit.
**************************
( I will replace all psid with #psidlist.psid#)
<cfquery name="psidlist" Datasource="#Request.datas
select psid
from a_rollup_dept
order by psid
</cfquery>
<cfquery name="qdirect" Datasource="#Request.datas
select
(select psid,
from a_rollup_labor
group by "#psidlist.psid#"),
(select sum(labor_hours) from a_rollup_labor
where labor_date = '01/01/2007'
group by psid) jan_salary,
(select sum(labor_hours) from a_rollup_labor
where d_i IN ('D','I')
and proj_def in ('##')
and activity_type like 'D%'
and rcc NOT in ('80507')
group by psid) ototal,
(select sum(labor_hours) from a_rollup_labor
where labor_date = '02/01/2007'
group by psid) feb_salary,
(select sum(labor_hours) from a_rollup_labor
where labor_date = '03/01/2007'
group by psid) mar_salary,
(select sum(labor_hours) from a_rollup_labor
where labor_date = '04/01/2007'
group by psid) apr_salary,
(select sum(labor_hours) from a_rollup_labor
where labor_date = '05/01/2007'
group by psid) may_salary,
(select sum(labor_hours) from a_rollup_labor
where labor_date = '06/01/2007'
group by psid) jun_salary
</cfquery>
<cfdump var="#qDirect#">
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That works! Cleaning up the SQL as you did was actually a better idea. I now want to mass load a table that already exists with the results of this query before displaying. I will open a new question for that.