Monthly Archives: October 2021

The maximum values for an integer

The maximum values for an integer in SQL Server are:

-2147483648 through 2147483647

And the byte size is 4 bytes.

Other maximum values:

BigInt: -9223372036854775808 through 9223372036854775807 (8 bytes)
SmallInt: -32768 through 32767 (2 bytes)
TinyInt: 0 through 255 (1 byte)

Get First and Last day of a week

Get first and last day of a week and set monday as te first day of the week

SET DATEFIRST 1

declare @Week int  set @Week = 40
declare @Year int  set @Year = 2021

select dateadd (week, @Week, dateadd (year, @Year-1900, 0)) - 4 -
         datepart(dw, dateadd (week, @Week, dateadd (year, @Year-1900, 0)) - 4) + 1

select dateadd (week, @Week, dateadd (year, @Year-1900, 0)) - 4 -
         datepart(dw, dateadd (week, @Week, dateadd (year, @Year-1900, 0)) - 4) + 6