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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 CASE Statement

Author  Topic 

JeffS23
Posting Yak Master

212 Posts

Posted - 2007-12-27 : 12:42:22
I need to execute a simple Case Statement. Strangely, if I include a comparison operator I receive an error message showing a syntax error (Message 102, Level 15). But the same statement without the operator works jsut fine.

Works:

Select LastName, Group =
Case Age
When 15 Then '1'
When 18 Then '2'
Else '20'
From tblAgeGroup
End

Does Not Work:

Select LastName, Group =
Case Age
When <15 Then '1'
When <18 Then '2'
Else '20'
From tblAgeGroup
End

Also, I noticed that this does not work in any other combination of the "When.." clause.

Any help is appreciated.

Thanks

nr
SQLTeam MVY

12543 Posts

Posted - 2007-12-27 : 12:43:22
Select LastName, Group =
Case
When Age<15 Then '1'
When Age<18 Then '2'
Else '20'
From tblAgeGroup
End

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-28 : 01:38:20
Thats why I suggested to always use CASE WHEN Expression instead of CASE Expression WHEN

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -