Category / MS SQL
-
MS SQL insert in the middle and reset auto increment
In case you need to insert something in the middle and need to set autoincremented column to some particular values, you can do the following: Set Identity_Insert [TableName] On -- Turn off…April 29, 2019 -
SQL query for today’s date minus year, month, day or minute
To add or subtract some date/time you can use MS SQL function: DATEADD(datepart, number, date) Let's say you need to add five months to current date, use this: SELECT * FROM YourTable…October 10, 2018 -
How to select first row in each group ordered by some columns
I'm just gonna show you an example how to select first row in each group of logins ordered by IsActive and Created columns, hope you will realise how it works. For example…February 1, 2018 -
Start of month from date in MS SQL (opposite to EOMONTH function)
Sometimes we need to select values grouped by month from MS SQL Table. Probably the easiest way to do it is to call function DateAdd with DateDiff: SELECT Sum(YourColumn), DATEADD(month, DATEDIFF(month, 0, [YourDateColumn]), 0)…October 9, 2016
Loading posts...