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)
 select case satement

Author  Topic 

cjcclee
Starting Member

33 Posts

Posted - 2008-01-11 : 09:23:00
Hi, all

ServiceYears is one of column of table.

select case ServiceYears
when >=14 then 14
else
serviceYears
end
from tablename


I always get 'Incorrect syntax near >' error message. if serviceyear greater than 14, return 14, else return serviceyear.

I do not know how to correct. Thanks!

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-01-11 : 09:25:02
[code]case when ServiceYears >=14 then 14
else ServiceYears
end[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-01-11 : 09:25:02
put like this:-

select case
when ServiceYears>=14 then 14
else
serviceYears
end
from tablename


Also make sure serviceYears is of int datatype
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-11 : 09:35:35
quote:
Originally posted by cjcclee

Hi, all

ServiceYears is one of column of table.

select case ServiceYears
when >=14 then 14
else
serviceYears
end
from tablename


I always get 'Incorrect syntax near >' error message. if serviceyear greater than 14, return 14, else return serviceyear.

I do not know how to correct. Thanks!


Thats why I suggest to always use CASE WHEN EXPRESSION than CASE EXPRESSION WHEN

Madhivanan

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

cjcclee
Starting Member

33 Posts

Posted - 2008-01-11 : 09:35:49
It works. Thanks so much both of you! I appreciated your help.
Go to Top of Page
   

- Advertisement -