⌘BABAKOV.NET Let's code!
100% [light] [ru]
~/databases/mssql $

MSSQL

38 total · page 4 / 4

OFFSET FETCH - Limiting Result Set in MSSQL

"OFFSET FETCH" is a filter that allows skipping a certain number of rows in the result set. For example: select field1, field2, field3 from table1 order by field1, field2 offset 100 rows fetch next 50 rows only; This example will return rows from 101 to 150, from all rows sorted by field1 and field2.

18 views 0 comments 0 likes ./Read →

Example of Date Range Selection in MSSQL

Example of Date Range Selection: WITH q AS ( SELECT 1 AS num UNION ALL SELECT num + 1 FROM q WHERE num < 10 ) SELECT DATEADD(DAY,0,cast(cast(DATEADD(DAY,-num,SYSDATETIME()) as date) as datetime)) FROM q Simple version of the example of selecting a range of numbers:

18 views 0 comments 0 likes ./Read →

Example of Error Catching in MSSQL

Example of how to catch errors in MSSQL. BEGIN TRY -- Some code that will return an error for example. SELECT 1/0; END TRY BEGIN CATCH SELECT ERROR_NUMBER() AS ErrorNumber ,ERROR_SEVERITY() AS ErrorSeverity ,ERROR_STATE() AS ErrorState ,ERROR_PROCEDURE() AS ErrorProcedure ,ERROR_LINE() AS ErrorLine ,ERROR_MESSAGE() AS ErrorMessage; END CATCH

17 views 0 comments 0 likes ./Read →