Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Can I use a Case statement in the Group By?

Author  Topic 

kelemvor
Starting Member

6 Posts

Posted - 2011-08-02 : 17:18:49
I have a Case statement to check the contents of a record. If the contents match a certain format, I use the data from the record. If the contents do not match the format, then I want it to be blank.


case
when query_string like 'Id=%' then query_string
else ''
end,


The problem is I need to output the results grouped by this column. So anything that matches the ID= will be grouped by whatever is in that record and everything else will all be grouped together.

Problem is if I put the case statement in the group by it doesn't like it.

Is there some other way to do this?

Thanks.

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-08-02 : 17:45:15
You should be able to use what you have shown in a group by statement. Can you post the full query and the exact error message you are getting?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-03 : 01:01:25
can you show you current group by statement?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -