Sql-запрос для поиска дней рождения и юбилеев
I have a CRON task that needs to extract customers with birthdays in a given date range, from a MySQL DB table. The birthday field is indexed and of type DATE. I want a query which should trigger on every Monday and extract all the customers who have birthday starting from next monday +10 days thereon. I'm using below query right now but here I have to manually change the month and date range. Need to automate it Please assist..
Что я уже пробовал:
DECLARE @Month INT=01 DECLARE @StarDate INT=01 DECLARE @EndDate INT=08 SELECT distinct Outlets.OutletName, Outlets.Locality, Outlets.City, FORMAT(Customers.DateOfBirth, 'dd/MMM')as DOB,DateOfBirth, Customers.CustomerName, Customers.Cell_Number, Customers.EmailId, Customers.Gender, Customers.AgeGroup FROM Customers WITH (NOLOCK) INNER JOIN CustomerActivities ON Customers.CustomerId=CustomerActivities.CustomerId INNER JOIN Outlets ON CustomerActivities.EntityId=Outlets.OutletId WHERE Customers.AccountId='wv5wdvf5v46sf2b16f5b16f2b' AND MONTH (DateOfBirth)=@Month AND DAY (DateOfBirth) >=@StarDate AND DAY (DateOfBirth) <= @EndDate Order By DateOfBirth ASC