Here is a simple T-SQL script that may come handy if you need the month end dates of last N months. N is the number of months. /* Assign the dynamic number of months here. You can write a procedure / table-valued function to accept this value as a parameter. */ DECLARE @Last_N_Months INT = … Continue reading Get the month end dates of last N months
Tag: T-SQL
Demystifying STUFF() function
This article will talk about myth with Stuff() function that it can be only used for concatenation. We'll do the reality check to demystify the Stuff() function.
T-SQL query to get the latest available backup chain
T-SQL query to return the latest available database backup chain (Full, Differential and Log) of individual databases along with their backup size and compressed size.
T-SQL script to purge all the tables including foreign key references
T-SQL script to purge all the tables including foreign key references. The script has been made smart enough to use TRUNCATE wherever there is no foreign key reference and to use DELETE wherever there is foreign key reference.
T-SQL query to copy data from one database to another database
T-SQL query to copy the rows of all the tables from one database to another database only if they have rows in Source DB and exact same Schema in both Source and Destination DB.