How to do something like IIf with Sql-query using Sql-Server 2000?

I mean my database table has bit(boolean) field, and if this bit field is on
(true) then calculation field should use other formula than when this
bit-field is not on (false) like ...

IIF(MyTable.BitField = true, "FieldA + FieldB", "FieldA + FieldC") AS
SumValue

I think this should be easy, but I haven't succeeded yet. Yes, I know this
is not Sql-query question, but I need this query with ADO.NET :)

--
Thanks in advance!

Mika

Re: SQL-query with ADO.NET by Mika

Mika
Tue Sep 07 06:16:58 CDT 2004

Sorry my writing error! Last text line should be ...

Yes, I know this is not Sql-query NG, but I need this query with ADO.NET :)


"Mika M" <mika.mahonen@nospam_kolumbus.fi> wrote in message
news:ORfanYMlEHA.712@TK2MSFTNGP09.phx.gbl...
> How to do something like IIf with Sql-query using Sql-Server 2000?
>
> I mean my database table has bit(boolean) field, and if this bit field is
> on (true) then calculation field should use other formula than when this
> bit-field is not on (false) like ...
>
> IIF(MyTable.BitField = true, "FieldA + FieldB", "FieldA + FieldC") AS
> SumValue
>
> I think this should be easy, but I haven't succeeded yet. Yes, I know this
> is not Sql-query question, but I need this query with ADO.NET :)
>
> --
> Thanks in advance!
>
> Mika
>



Re: SQL-query with ADO.NET by Miha

Miha
Tue Sep 07 06:53:47 CDT 2004

Hi Mika,

Straight from the sql server help files (CASE statament):
SELECT 'Price Category' =
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,
CAST(title AS varchar(20)) AS 'Shortened Title'
FROM titles
ORDER BY price


--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Mika M" <mika.mahonen@nospam_kolumbus.fi> wrote in message
news:ORfanYMlEHA.712@TK2MSFTNGP09.phx.gbl...
> How to do something like IIf with Sql-query using Sql-Server 2000?
>
> I mean my database table has bit(boolean) field, and if this bit field is
> on (true) then calculation field should use other formula than when this
> bit-field is not on (false) like ...
>
> IIF(MyTable.BitField = true, "FieldA + FieldB", "FieldA + FieldC") AS
> SumValue
>
> I think this should be easy, but I haven't succeeded yet. Yes, I know this
> is not Sql-query question, but I need this query with ADO.NET :)
>
> --
> Thanks in advance!
>
> Mika
>