-- OFFSET AND FETCH is used to get records for selected range
SELECT *
FROM my_master_table
ORDER BY id
OFFSET 10 ROWS
FETCH NEXT 10 ROWS ONLY;
-- RAISEERROR Replaced By THROW
BEGIN TRY
SELECT 'Using Throw'
SELECT 1 / 0
END TRY
BEGIN CATCH
--Throw error
THROW
END CATCH
-- Some more Date Time Formats
SELECT DATEFROMPARTS(2012, 02, 12) AS DATE_FROMPARTS,
DATETIME2FROMPARTS(2012, 02, 12, 13, 30, 5, 1, 7) AS DATETIME2_FROMPARTS,
DATETIMEFROMPARTS(2012, 02, 12, 13, 30, 5, 997) AS DATETIME_FROMPARTS,
DATETIMEOFFSETFROMPARTS(2012, 02, 12, 13, 30, 5, 1, -8, 0, 7) AS DATETIMEOFFSET_FROMPARTS,
SMALLDATETIMEFROMPARTS(2012, 02, 12, 13, 30) AS SMALLDATETIME_FROMPARTS,
TIMEFROMPARTS(13, 30, 5, 1, 7)AS TIME_FROMPARTS;
-- CHOOSE function
SELECT CHOOSE ( 2, 'A', 'B', 'C', 'D' ) AS Result;
SELECT TOP 4 id, CHOOSE (id, 'A','B','C','D','E') AS Expression1
FROM my_master_table
SELECT TOP 20 first_name + SPACE(1) + ISNULL(last_name,''), created, CHOOSE(MONTH(created),'Jan','Feb', 'Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec') AS Quarter_Hired
FROM my_contact_user
WHERE YEAR(created) > 2010
ORDER BY YEAR(created);
-- IIF function
DECLARE @a int = 10, @b int = 20;
SELECT IIF ( @a > @b, 'TRUE', 'FALSE' ) AS Result;
-- With RESULT SETS, help you to get result set form SP from your own data format
CREATE PROCEDURE SP_NAME_Temp
AS
BEGIN
SELECT 1 AS NO, 'result' AS Feature, GETDATE() currDate
UNION ALL
SELECT 1 AS NO,'result' AS Feature, GETDATE() currDate
UNION ALL
SELECT 1 AS NO, 'result' AS Feature, GETDATE() currDate
UNION ALL
SELECT 1 AS NO, 'result' AS Feature, GETDATE() currDate
END
EXEC SP_NAME_Temp
WITH RESULT SETS
(
(
numId INT,
nameType VARCHAR(50),
dateType VARCHAR(50)
)
)
-- CONCAT : for concatenating more than one strings or columns
SELECT TOP 10 CONCAT( first_name, last_name ) AS Result
FROM my_contact_user
-- FORMAT
DECLARE @d DATETIME = GETDATE();
SELECT FORMAT( @d, 'dd/MM/yyyy', 'en-US' ) AS 'DateTime Result'
,FORMAT(123456789,'###-##-####') AS 'Custom Number Result',FORMAT(4565213, 'C', 'en-us') AS 'Currency Format';
SELECT FORMAT(GETDATE(),'dd/MMM/yyyy') +' '+ FORMAT(GETDATE(), 'hh:mm tt')