May 1, 2006 at 11:30 am
I believe the following is a straight forward code but it is giving me error message
error message:
Server: Msg 164, Level 15, State 1, Line 17
GROUP BY expressions must refer to column names that appear in the select list.
code:
Declare @curr_Month Datetime, @Prev_Month Datetime
Set @curr_Month='5/31/2005'
Set @Prev_Month = '4/30/2005'
Select Convert(varchar(25),(CAST (@PREV_MONTH AS VARCHAR(11)) + '-'+ CAST (@CURR_MONTH AS VARCHAR(11)))),C_MARKETPLACE, C_FSM
FROM (SELECT MARKETPLACE C_MARKETPLACE, FSM C_FSM, MARKETPLACE+FSM AS MATCH_KEY FROM MB_RPT_ROSTER_ARCHIVE
WHERE RPT_WEEK=@CURR_MONTH GROUP BY MARKETPLACE, FSM, MARKETPLACE+FSM) CURR_ROSTER LEFT OUTER JOIN
(SELECT MARKETPLACE, FSM, MARKETPLACE+FSM AS MATCH_KEY FROM MB_RPT_ROSTER_ARCHIVE
WHERE RPT_WEEK=@PREV_MONTH GROUP BY MARKETPLACE, FSM, MARKETPLACE+FSM) PREV_ROSTER
ON CURR_ROSTER.MATCH_KEY=PREV_ROSTER.MATCH_KEY
where PREV_ROSTER.MATCH_KEY is null
GROUP BY Convert(varchar(25),(CAST (@PREV_MONTH AS VARCHAR(11)) + '-'+ CAST (@CURR_MONTH AS VARCHAR(11)))),C_MARKETPLACE, C_FSM
Please help...................
May 1, 2006 at 11:50 am
I don;t have your schema to test, but Ib elieve its this
Convert(varchar(25),(CAST (@PREV_MONTH AS VARCHAR(11)) + '-'+ CAST (@CURR_MONTH AS VARCHAR(11))))
This derived field is not a column in your dataset so it cannot group by. Remove this, and the error goes away.
Not sure though
May 2, 2006 at 5:45 am
This line...
Convert(varchar(25),(CAST (@PREV_MONTH AS VARCHAR(11)) + '-'+ CAST (@CURR_MONTH AS VARCHAR(11))))
...is this one causing the problem, but I'm wondering why you would want to group by static data anyway? @PREV_MONTH and @CURR_MONTH will never change, so grouping by them will have no effect on the results.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply