BeachSandGuy
Programmer
Hi, I searched and couldn't find an answer in this forum. I have a query using the group by function to aggregate weekly volumes of calls and dumping into a separate databse. It is designed to be automated, so requires for each pull to include the beginning of the week date. However my function to pull the start of week date has a constant in it which gives me the error "Each GROUP BY expression must contain at least one column that is not an outer reference." Can anyone think of a workaround? I really need that date field in there. Thanks for any help. Here is a snippet of that code:
Ian
Code:
Select
[B](DateAdd(d, -((@@DATEFIRST + DatePart(dw, (CAST( FLOOR( CAST( getDate() AS FLOAT ) ) AS DATETIME ) -7)) -2) % 7),
(CAST( FLOOR( CAST( getDate() AS FLOAT ) ) AS DATETIME ) -7))) as StartofWeek[/b],
BUSINESS_UNIT.business_unit_nm as 'BU',
smry_tcd_transfers.node as 'Node', smry_tcd_calls.skillgroupperipheralnumber as 'OriginalSkill',
Count(start_dttm) as CallCount
from smry_tcd_transfers
inner join smry_tcd_calls on smry_tcd_transfers.vcc_call_var_key_id = smry_tcd_calls.call_id and smry_tcd_transfers.agent_id = smry_tcd_calls.agent_id
inner join BUSINESS_UNIT on BUSINESS_UNIT.business_unit_id = smry_tcd_calls.business_unit_id
where
smry_tcd_transfers.start_dttm >= DateAdd(d, -((@@DATEFIRST + DatePart(dw, (CAST( FLOOR( CAST( getDate() AS FLOAT ) ) AS DATETIME ) -7)) -2) % 7),(CAST( FLOOR( CAST( getDate() AS FLOAT ) ) AS DATETIME ) -7))
AND smry_tcd_transfers.start_dttm <= (DateAdd(d, -((@@DATEFIRST + DatePart(dw, (CAST( FLOOR( CAST( getDate() AS FLOAT ) ) AS DATETIME ) -7)) -2) % 7),(CAST( FLOOR( CAST( getDate() AS FLOAT ) ) AS DATETIME ) -7))) + 5
Group By
[B](DateAdd(d, -((@@DATEFIRST + DatePart(dw, (CAST( FLOOR( CAST( getDate() AS FLOAT ) ) AS DATETIME ) -7)) -2) % 7),(CAST( FLOOR( CAST( getDate() AS FLOAT ) ) AS DATETIME ) -7)))[/B],
BUSINESS_UNIT.business_unit_nm,
smry_tcd_transfers.node, smry_tcd_calls.skillgroupperipheralnumber
Ian