Write a SQL code that finds how many days away from thanksgiving. The code should work in any month in this year 2020.
write a code to find the oldest person from a table has an age column.
NOTE: please use ssms to write the code with a screenshot of the output.
SQL code to find how many days away from thanksgiving.
declare @anydate datetime='2020-01-01'
declare @dt datetime='20201101'
Select @dt=dateadd(month,10,dateadd(year,
datediff(year,0,@anydate),0)) ---November 1st
select DateAdd(day, (7+5 -DatePart(weekday, @dt))%7, @dt)
firstThuIntheMonth
select DATEADD(WEEK, 3, DATEADD(d, Case when DATEPART(dw, @dt)>5
Then 7 Else 0 ENd + (5 - DATEPART(dw, @dt)), @dt))
Thanksgivingday
Select DATEADD(WEEK, 3, DateAdd(day, (7+5 -DatePart(weekday,
@dt))%7, @dt) ) Thanksgivingday
SQL Code to find the oldest person from a table has an age column.
Select * from person where age =
(Select max(age) from person).
Get Answers For Free
Most questions answered within 1 hours.