Thursday, 22 July 2010

How can you use IIf in Transact-SQL?

While migrating our Access system to SQL Server i've always hated when i come across IIf statement. This is because i can't directly use the statement in Transact SQL, i must use Case statement instead.

Today, just 30 minutes before 6:00 pm (supposedly my time to go home), i 'met' the IIf statement that makes hell of my day.....

IIf(IsNull([List of FBM 100 Stocks].[KLCI Weight]),IIf(IsNull([List of Investment Stocks].[Stock Classification]),IIf([Asset Group].[Class]="Equities","Trading",[List of Investment Stocks].[Stock Classification]),[List of Investment Stocks].[Stock Classification]),[List of FBM 100 Stocks].[Stock Classification]) AS [Investment Classification]

Oh gosh... how do i convert this into Case statement....???!!!
I've tried several times to no avail....
Then I gave up at 6:30 pm, after one hour of hard work, no smart attempts, a headache and heartache (luckily no heart attack)....
now, tonight while blogging i'll try to solve the puzzle....
am i not a good programmer?

for more info on Case statement: http://www.sql-server-performance.com/faq/iif_tsql_p1.aspx

Just sharing....

No comments:

Post a Comment