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
 .NET Inside SQL Server (2005)
 How to use > and < operators in Case Condition

Author  Topic 

ravurugopinath@gmail.com
Starting Member

5 Posts

Posted - 2009-04-24 : 07:19:52
Hi,

Below is my query

SELECT [T25_Quote_No], [T25_TotalQuote1],
Budget = CASE [T25_TotalQuote1]
WHEN [T25_TotalQuote1] > 20.00 THEN 'Expensive'
WHEN [T25_TotalQuote1] BETWEEN 10.00 AND 19.99 THEN 'Moderate'
WHEN [T25_TotalQuote1] < 10.00 THEN 'Inexpensive'
ELSE 'Unknown'
END,
FROM [T25_tblQuote]

but after executing i am getting error

Msg 102, Level 15, State 1, Line 3
Incorrect syntax near '>'.

What is problem in my query ...Can't i use operators in case conditions?

Please help me

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-04-24 : 07:23:18
I think it is the comma between END and FROM.
Also the extra [T25_TotalQuote1] after the case should be removed.




E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-04-24 : 07:23:35
[code]SELECT [T25_Quote_No],
[T25_TotalQuote1],
CASE
WHEN [T25_TotalQuote1] > 20.00 THEN 'Expensive'
WHEN [T25_TotalQuote1] BETWEEN 10.00 AND 19.99 THEN 'Moderate'
WHEN [T25_TotalQuote1] < 10.00 THEN 'Inexpensive'
ELSE 'Unknown'
END AS Budget
FROM [T25_tblQuote][/code]


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -