Home > Archive > Microsoft SQL Server forum > September 2005 > inline if









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author inline if
Dima Gofman

2005-09-21, 9:24 am

I want to execute something like

select iif(type='credit',am
ount*-1,amount) from table

how can i do that? help file says iif is used in Multidimensional
Expressions but that seems overly complicated for this task.

any ideas?

Erland Sommarskog

2005-09-21, 9:24 am

Dima Gofman (dg@cfa-solutions.com) writes:
> I want to execute something like
>
> select iif(type='credit',am
ount*-1,amount) from table
>
> how can i do that? help file says iif is used in Multidimensional
> Expressions but that seems overly complicated for this task.


SELECT CASE type WHEN 'credit' THEN -1 ELSE 1 END * amount

See further the CASE expression in Books Online.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com