Change varchar column length, when column does not match given length in T-SQL.

The following code will update a column to varchar(max) only, when it does not already have the varchar(max) length. — Update column ‘Name’ length, it should be varchar(max). — Note: varchar(max) has length ‘-1’. if ( ( select character_maximum_length from information_schema.columns where table_name=object_name(object_id(‘dbo.Table1’)) and COLUMN_NAME = ‘Name’ ) <> -1 …

How to get the amount of elapsed minutes in current quarter in T-SQL

If you want to know the amount of elapsed minutes in the current quarter, you can use the following T-SQL code: declare @CurrentDateTime datetime = ‘2014-03-27 10:56:10’ declare @MinutesPassedInHour int = convert(int, datepart(minute, @CurrentDateTime)) declare @quarterCount int = @MinutesPassedInHour / 15 declare @MinutesPassedInQuarter int = (@MinutesPassedInHour – (@quarterCount * 15)) …