This is a nice sql query, I was afraid with a table and finally i got WITH CASE which helped me to implement confition in query. nice……..
SELECT CASE WHEN price IS NULL THEN ‘Not yet priced’ WHEN price = 10 and price THEN ‘Very Reasonable Title’ WHEN price >= 10 and price <= 20 THEN ‘Coffee Table Title’ ELSE ‘Expensive book!’ END AS “Price Category”, CONVERT(varchar(20), title) AS “Shortened Title” FROM pubs.dbo.titles ORDER BY price
very confusing way of helping others. no formatting at all so the beginner will not understand.
This query is not work in Microsoft SQL. Please use this:
SELECT CASE
WHEN price IS NULL THEN ‘Not yet priced’
WHEN price = 10 and price <= 20 THEN ‘Coffee Table Title’
ELSE ‘Expensive book!’
END
AS [Price Category], CONVERT(varchar(20), title) AS [Shortened Title] FROM pubs.dbo.titles ORDER BY price
good reply
SELECT CASE WHEN price IS NULL THEN ‘Not yet priced’
WHEN price = 10 THEN
‘Very Reasonable Title’
WHEN price >= 10 and price <= 20 THEN ‘Coffee Table Title’
ELSE ‘Expensive book!’ END
AS ‘Price Category’,
CONVERT(varchar(20), title) AS ‘Shortened Title’
FROM pubs.dbo.titles ORDER BY price
Loosers…..petty discussion
thnks for query…
good article. it solved my problem
good
Good