MySQL IF() equavalent ADO.NET function

  • Thread starter Thread starter Shiplu
  • Start date Start date
S

Shiplu

hi,
I am looking for a function in ADO.NET.
it's like IF() in MySQL.
suppose a table,

[sample_table]
memo, name, sex, amount
1, cust1, 'M',100
2, cust2, 'F', 200
3, cust2, 'F', 230
5, cust4, 'F', 460
6, cust1, 'M',70

In MySQL I would query "SELECT name, IF(sex='M','GUY','LADY') as type,
amount from sample_table where memo < 5";

and the result set,
name type amount
cust1 GUY 100
cust2 LADY 200
cust2 LADY 230
---------------------------------------------------------------------

now, I want this result set from that table.
what would be the equavalent query or IF() function in ADO.NET ?

please help !
I am stuck,
 
Shiplu,

The sql that you use depends on the database you are accessing. ADO.Net does
not have a built-in sql dialect.

Kerry Moorman
 
Shiplu,

You can use the Jet OLEDB provider to work with CSV files.

With that provider, you should be able to use the IIF function, as Edwin
pointed out in his reply.

Kerry Moorman
 
Shiplu said:
hi,
I am looking for a function in ADO.NET.
it's like IF() in MySQL.
suppose a table,

[sample_table]
memo, name, sex, amount
1, cust1, 'M',100
2, cust2, 'F', 200
3, cust2, 'F', 230
5, cust4, 'F', 460
6, cust1, 'M',70

In MySQL I would query "SELECT name, IF(sex='M','GUY','LADY') as type,
amount from sample_table where memo < 5";

and the result set,
name type amount
cust1 GUY 100
cust2 LADY 200
cust2 LADY 230

SELECT name,
CASE sex
WHEN 'M' THEN 'GUY'
ELSE 'LADY'
END as type,
amount
FROM sample_table
WHERE memo < 5


a lot of 'normal' database system, e.g. databases which are mature,
support a CASE statement, often with the syntaxis used above.

FB


--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 
Back
Top