EndlessNights
Programmer
Hiya,
I'm trying to run a nested query that will extract for each date a count on certain variables. I'm hoping to get something like this:
TheYear, TheMonth, TheDay, count(Variable=whatever1), count(Variable=whatever2), etc...
Below is a much simplified version of what I'm trying to accomplish:
select
'TheDay' = DatePart(d, TB1.DateStamp),
'Variable1' = (
select count(TB2.ID)
from TableName TB2
where Variable1 = 'whatever' and
DatePart(d, TB2.DateStamp) = DatePart(d, TB1.DateStamp)
)
from TableName TB1
group by DatePart(d, TB1.DateStamp)
Unfortunately I keep getting this error:
Server: Msg 8630, Level 17, State 38, Line 1
Internal Query Processor Error: The query processor encountered an unexpected error during execution.
I know the larger select works without the nested selects, and I know the nested select works when not included in the larger statement and I use hard coded numbers (e.g. DatePart(d, TB1.DateStamp) is replaced by 8 for example)...
So what am I doing wrong?!?!
Any suggestions would be great!
cheers,
mike
I'm trying to run a nested query that will extract for each date a count on certain variables. I'm hoping to get something like this:
TheYear, TheMonth, TheDay, count(Variable=whatever1), count(Variable=whatever2), etc...
Below is a much simplified version of what I'm trying to accomplish:
select
'TheDay' = DatePart(d, TB1.DateStamp),
'Variable1' = (
select count(TB2.ID)
from TableName TB2
where Variable1 = 'whatever' and
DatePart(d, TB2.DateStamp) = DatePart(d, TB1.DateStamp)
)
from TableName TB1
group by DatePart(d, TB1.DateStamp)
Unfortunately I keep getting this error:
Server: Msg 8630, Level 17, State 38, Line 1
Internal Query Processor Error: The query processor encountered an unexpected error during execution.
I know the larger select works without the nested selects, and I know the nested select works when not included in the larger statement and I use hard coded numbers (e.g. DatePart(d, TB1.DateStamp) is replaced by 8 for example)...
So what am I doing wrong?!?!
Any suggestions would be great!
cheers,
mike