SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

ajaypal
Starting Member

Canada
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
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
Constraint Violating Yak Guru

373 Posts

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

visakh16
Very Important crosS Applying yaK Herder

India
52317 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
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22755 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

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.06 seconds. Powered By: Snitz Forums 2000