December 3, 2008 at 3:55 am
I currently have a select where for one of the fields I need to change the output if it is null or contains the code 'v918899' For eveything else just display the contents. Effectively the logic I want is:
If code is null then change to '5K5'
If code is = 'V918899' THEN CHANGE TO '5k5'
ELSE display code.
I have tried to use a case statement but it dosen't seem to work. ANy ideas?
December 3, 2008 at 4:06 am
eseosaoregie (12/3/2008)
I currently have a select where for one of the fields I need to change the output if it is null or contains the code 'v918899' For eveything else just display the contents. Effectively the logic I want is:If code is null then change to '5K5'
If code is = 'V918899' THEN CHANGE TO '5k5'
ELSE display code.
I have tried to use a case statement but it dosen't seem to work. ANy ideas?
You need a searched CASE like this:
CASE WHEN code IS NULL OR code = 'V918899' THEN '5K5' ELSE code END
Cheers
ChrisM
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
December 3, 2008 at 4:12 am
December 3, 2008 at 4:26 am
Cheers that works.
December 4, 2008 at 9:57 pm
Try this alternate coding ...
Its only a way of rewriting existing formats suggested by other learned members from the forum :-
CASE WHEN ISNULL([FieldName], '5K5') = 'V918899'
THEN '5K5'
ELSE ISNULL([FieldName], '5K5')
END CASE
December 4, 2008 at 10:51 pm
One more way: COALESCE(NULLIF(code,'V918899'), '5K5')
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply