March 2, 2009 at 8:48 am
how do i convert
IIf([x]="YEN","JPY",IIf([x]="EURO","EUR",[x])) AS InvCurr
to SQL?
March 2, 2009 at 8:49 am
Have you looked up CASE in BOL (Books Online)?
March 2, 2009 at 8:52 am
Hmm, I think it's this:
CASE x
When 'YEN' Then 'JPY'
When 'EURO' Then 'EUR'
End AS InvCurr
[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]
March 2, 2009 at 8:59 am
RBarryYoung (3/2/2009)
Hmm, I think it's this:
Needs the else block as well
CASE x
When 'YEN' Then 'JPY'
When 'EURO' Then 'EUR'
ELSE x
End AS InvCurr
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
March 2, 2009 at 9:15 am
Gail: Oops, I missed the last "x"! ...
Lynn: Thanks, but as Gail pointed out, I was not entirely correct.
Edit: Said "was", should have said "was not". slight difference... :w00t:
[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]
March 2, 2009 at 9:23 am
RBarryYoung (3/2/2009)
Gail: Oops, I missed the last "x"! ...Lynn: Thanks, but as Gail pointed out, I was not entirely correct.
Edit: Said "was", should have said "was not". slight difference... :w00t:
There is, of course, a "depends" here. You gave the OP EXACTLY what he asked for in his post. The ELSE is not required, but it is highly recommended in case you have values that don't match any of your WHEN clauses.
March 2, 2009 at 9:32 am
Lynn Pettis (3/2/2009)
You gave the OP EXACTLY what he asked for in his post.
Nope. Barry's solution equates to IIf([x]="YEN","JPY",IIf([x]="EURO","EUR",NULL)) , ie
If X = 'Yen' then 'JPY' ELSE If X = 'Euro' then 'Eur' Else Null,
however the OP's IIF statement was
If X = 'Yen' then 'JPY' ELSE If X = 'Euro' then 'Eur' Else X
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
March 2, 2009 at 9:36 am
GilaMonster (3/2/2009)
Lynn Pettis (3/2/2009)
You gave the OP EXACTLY what he asked for in his post.Nope. Barry's solution equates to IIf([x]="YEN","JPY",IIf([x]="EURO","EUR",NULL)) , ie
If X = 'Yen' then 'JPY' ELSE If X = 'Euro' then 'Eur' Else Null,
however the OP's IIF statement was
If X = 'Yen' then 'JPY' ELSE If X = 'Euro' then 'Eur' Else X
Sorry, I missed the [x] at the end. Must be more exhausted than I thought after this weekend on the pitch.
Well, Barry's answer was still better than that provided in the OP's other post.
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply