Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 CASE function not working

Author  Topic 

parrot
Posting Yak Master

132 Posts

Posted - 2009-03-24 : 11:08:40
For some reason the CASE function using SQL 2005 is not working in my C# program anymore. It used to work but now I get an error with the following SQL command:

SELECT EE.Employee, CASE WHEN EE.Sex = 'F' THEN 'Female' WHEN EE.Sex = 'M' THEN 'Male' END "Sex" FROM EE

The error message says -

System.Data.OleDb.OleDbException:IErrorInfo.GetDescription failed with E_FAIL(0x80004005)

I also tried it with the following SQL command and get the same error.

SELECT EE.Employee, CASE Sex WHEN 'F' THEN 'Female' WHEN 'M' THEN 'Male' END "Sex" FROM EE

Can anyone tell what's wrong with this command? Something changed somewhere!

parrot
Posting Yak Master

132 Posts

Posted - 2009-03-24 : 11:33:08
I should mention that I do not have this error if I run the application on a computer using SQL Server 2000. It only happens on SQL 2005 and I have applied the latest service pack.
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-03-24 : 11:37:32
[code]SELECT EE.Employee, CASE WHEN EE.Sex = 'F' THEN 'Female' WHEN EE.Sex = 'M' THEN 'Male' END 'Sex' FROM EE[/code]
Go to Top of Page

parrot
Posting Yak Master

132 Posts

Posted - 2009-03-24 : 11:46:16
I found out the problem. Somehow my program was copied over from another system that performs the same functions but uses an Access data base rather than an SQL database. Therefore, the problem is that Access does not recognize the CASE function. Does anyone know if there is an equivalent for the CASE function when using an Access database?
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-03-24 : 11:55:51
nested IIF or switch commands should help.
Go to Top of Page

parrot
Posting Yak Master

132 Posts

Posted - 2009-03-24 : 12:10:30
I want to replace the CASE command in an SQL statement, not in my C# logic.
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-03-24 : 12:20:09
You asked this,
quote:

Does anyone know if there is an equivalent for the CASE function when using an Access database?


The anser to which is,, nested IIF or switch commands.

Makes sense ?
Go to Top of Page

parrot
Posting Yak Master

132 Posts

Posted - 2009-03-24 : 12:50:28
I understand that I asked the question incorrectly but I need to be able to do a data conversion in Access within the SQL statement similar to a CASE statement in SQL. I looked up the documentation on the JET40 help file and there doesn't seem to be an equivalent.
Go to Top of Page
   

- Advertisement -