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
 General SQL Server Forums
 New to SQL Server Programming
 Alternative of Case in SQL

Author  Topic 

ajaypal
Starting Member

6 Posts

Posted - 2013-07-19 : 15:46:35
Hi Friends ,

I am testing a data migration project and in that I have to confirm if data is migrated as expected . In most of the cases I have requirements in If - Else format for example : -

If Table_Name.Column_Name = 'a'
set New_Column = 1
If Else Table_Name.Column_Name = 'b'
set New_Column = 2
Else
set New_Column = 3

and It could go even crazier .
Right now I am doing unit testing and just picking 10 records and then comparing to the target. In this scenario if I use CASE , I might miss the coverage because I may not use some conditions in my testing. I can create different test cases but this is not efficient.

So cold you please suggest me a Select statement which will select at-least one if condition values.

Thanks

bitsmed
Aged Yak Warrior

545 Posts

Posted - 2013-07-19 : 16:41:20
As of version 2012, MSSQL supports IIF (See [url]http://msdn.microsoft.com/en-us/library/hh213574.aspx[/url]).
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-07-20 : 08:09:34
You could create a select to get data from source by applying a filter using IN to get all possible values. Then you can apply the mapping logic based on CASE ..WHEN or IIF to get corresponding values and check it against the values in your migrated table.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2013-07-23 : 08:48:44
Alternatively you can have a mapping table that has column values and mapping values and join with the source table

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -