Friday, February 24, 2012

can any body tell me what wrong in my sql statement

Hi,

can any body tell me what is wrong in my sql statement

SELECT title, price,

Budget

=CASE priceWHEN price> 20.00THEN'Expensive'WHEN priceBETWEEN 10.00AND 19.99THEN'Moderate'WHEN price< 10.00THEN'Inexpensive'ELSE'Unknown'END

FROM

titlesit gives me this error

Msg 170, Level 15, State 1, Line 3

Line 3: Incorrect syntax near '>'.

but when i use somthing like that i will works fine

SELECT

Budget

i am using sql server 2000

SELECT title, price, Budget=CASEWHEN price < 10.00THEN'Inexpensive'WHEN price < 20.00THEN'Moderate'WHEN priceISNULLTHEN'Unknown'ELSE'Expensive'ENDFROMtitles

I'm assuming that price is a Decimal datatype.

|||
Take the price after CASE out. There are two forms of CASE statement. Your syntax was wrong. 
SELECT title, price, Budget=CASE
WHEN price> 20.00THEN'Expensive'
WHEN
priceBETWEEN 10.00AND 19.99THEN'Moderate'
WHEN
price< 10.00THEN'Inexpensive'
ELSE
'Unknown'
END
FROMtitles


No comments:

Post a Comment