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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Alternative of Case in SQL
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

6 Posts

Posted - 07/19/2013 :  15:46:35  Show Profile  Reply with Quote
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
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.


Aged Yak Warrior

545 Posts

Posted - 07/19/2013 :  16:41:20  Show Profile  Reply with Quote
As of version 2012, MSSQL supports IIF (See
Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 07/20/2013 :  08:09:34  Show Profile  Reply with Quote
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
Go to Top of Page

Premature Yak Congratulator

22864 Posts

Posted - 07/23/2013 :  08:48:44  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
Alternatively you can have a mapping table that has column values and mapping values and join with the source table


Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000