Sql server query for datediff

sql server query for datediff — DOES NOT ACCOUNT FOR LEAP YEARS DECLARE @date1 DATETIME, @date2 DATETIME, @result VARCHAR(100); DECLARE @years INT, @months INT, @days INT, @hours INT, @minutes INT, @seconds INT, @milliseconds INT; SET @date1 = ‘1900-01-01 00:00:00.000’ SET @date2 = ‘2018-12-12 07:08:01.123’ SELECT @years = DATEDIFF(yy, @date1, @date2) IF DATEADD(yy, [email protected], @date2) < […]

Sql server query for datediff Read More

Sql last week

sql last week select min(date), max(date) from calendar where week = datepart(week, getdate() – 7) and year = datepart(year, getdate() – 7) sql select data from last week select id from tbname where date between date_sub(now(),INTERVAL 1 WEEK) and now();

Sql last week Read More

Sql how to partition rank

how to use rank function in sql BY LOVE SINGH, Here, name and id is the column name of the table tbltest. SELECT name, RANK () OVER ( ORDER BY id DESC ) price_rank FROM tbltest; sql how to partition rank SELECT * FROM ( SELECT product_id, product_name, brand_id, list_price, RANK () OVER ( PARTITION […]

Sql how to partition rank Read More