Description:
Query:
In this example
we explain that how to find upcoming birthday for the upcoming week using SQL Query.
Or SQL Query to find the Next Week Record from the database. Or how to find
Next Week upcoming birthday list using SQL Query. Or how to get the list of the
Next week records using SQL Query.
So here we demonstrate
that how to find upcoming birthday list or the list of the birthday records
that are comes in Next week using SQL Server. Here we add list of the SQL Query
to find the appropriate record or the Date Rage as you want.
DECLARE @InNextDays INT;
SET @InNextDays = 7;
--
Query to find workers, whose birthday is in given number of days
SELECT *
FROM @Workers
WHERE DATEADD(
Year, DATEPART( Year, GETDATE()) - DATEPART( Year, DOB), DOB)
BETWEEN CONVERT( DATE, GETDATE())
AND CONVERT( DATE, GETDATE() + @InNextDays);
-- Query to find
workers, whose birthday is in current week
SELECT *
FROM Employee
WHERE DATEPART(
Week, DATEADD( Year, DATEPART( Year, GETDATE()) - DATEPART( Year, DOB), DOB))
= DATEPART( Week, GETDATE());
select dateadd(wk, datediff(wk, 0, getdate()) - 1, 0) --first day of last week
, dateadd(wk, datediff(wk, 0, getdate()), 0) --first day of this week
select dateadd(wk, datediff(wk, 0, getdate()), 0) --first day of this
week
, dateadd(wk, datediff(wk, 0, getdate())+1, 0) --first day of Next or
upcoming week
0 comments:
Post a Comment