September 14, 2012 at 7:16 am
Hi,
am having two columns
Usage, Expiration date.
My requirement is : when "usage" column is blank "expiration_date" should not come in select,
Am using below logic, but it is not working.
select
case when ( rtrim(e.usage)is null OR RTRIM (e.usage) = '') then ''
else ' Usage Rights: ' + rtrim(e.usage) end +
case when ( rtrim(e.expiration_date)is null OR RTRIM (e.expiration_date) = '') then ''
else ' (Expires ' + rtrim(convert(varchar, e.expiration_date,107)) + ')' end
usage_rights from ustest e
September 14, 2012 at 7:50 am
What isn't working about it. Do you get an error message? Get the wrong results? Something else?
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
September 14, 2012 at 7:50 am
Skanda (9/14/2012)
Hi,am having two columns
Usage, Expiration date.
My requirement is : when "usage" column is blank "expiration_date" should not come in select,
Am using below logic, but it is not working.
select
case when ( rtrim(e.usage)is null OR RTRIM (e.usage) = '') then ''
else ' Usage Rights: ' + rtrim(e.usage) end +
case when ( rtrim(e.expiration_date)is null OR RTRIM (e.expiration_date) = '') then ''
else ' (Expires ' + rtrim(convert(varchar, e.expiration_date,107)) + ')' end
usage_rights from ustest e
Can you define not working? Are you getting an error? Are the results not what you expect? Can you post some ddl (create table scripts), sample data (insert statements) and desired output based on your sample data?
Take a look at the first link in my signature for best practices when posting questions.
Can you explain your requirements?
when "usage" column is blank "expiration_date" should not come in select,
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply