New Logical Function CHOOSE in SQL Server 2012
As I describes before too that SQL Server 2012 came with so many different powerful functions which makes developer’s life very easy. I came up with one new logical functions CHOOSE today. If you want to look at earlier article of new functions of SQL Server 2012, have a look at following links:
|Function||Link to learn|
CHOOSE function accept the list of value along with Index and return the value based on the index passes to function. Let us see one small example.
IF OBJECT_ID('tempdb..#FunctionTesting') IS NOT NULL DROP TABLE #FunctionTesting CREATE TABLE #FunctionTesting ( ID INT IDENTITY(1,1) ,EmpName VARCHAR(50) ,NightShiftDay INT ) INSERT INTO #FunctionTesting VALUES ('Ritesh Shah',1) ,('Rajan Shah',2) ,('Bihag Thakar',3) ,('Kavan Dhruv',4) ,('Paresh Prajapati',5) ,('Kalu Bhuva',6) ,('Prapa Acharya',7) SELECT CHOOSE(NightShiftDay,'Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday') AS NightShiftDay ,EmpName FROM #FunctionTesting
Once you will execute above given SELECT query, you will get day name as against day number along with employee name. Here is the output of above query:
Reference: Ritesh Shah
Note: Microsoft Books online is a default reference of all articles.