Use northwindgocreate function udf_getstar (@ DateTime) Returns varchar (100) - Returns the date belonging, if there is a static constellation control code table directly in the query than beginreturn (- Declare @ DateTime - set @ = getDate () SELECT MAX (STAR) from (Select 'Capricorn' AS Star, 1 As [Month], 1 AS [Day] Union All Select 'Aquarius', 1, 20UNION All Select 'Pisces', 2,19Union All Select 'Peony Block', 3, 21UNION All Select 'Golden Block', 4, 20Union All Select 'Double Subshot', 5,21 ELON All Select 'Cancer', 6,22une All Select 'Leo, 7,23union All Select' Virgin Block ', 8, 23Union All Select' Libra ', 9, 23Union All Select' Scorpio ', 10, 24Union All Select' Sagittarius', 11, 22UNION All Select 'Capricorn', 12, 22) Starswhere [Month] * 40 [day] = (SELECT MAX ([Month] * 40 [day]) from (SELECT 'Capricorn' AS Star, 1 as [Month], 1 as [Day] Union All Select 'Aquarius' , 1, 20UNION All Select 'Pisces', 2,19Union All Select 'Peony Block', 3,21 UNION All Select 'Golden Block', 4, 20Union All Select 'Double Subshot', 5,21union All Select 'Cancer', 6, 22Union All Select 'Leo, 7, 23Union All Select' Virgo ', 8, 23Union All Select' Libra ', 9, 23Union All Select' Scorpio ', 10, 24UNION All Select' Sagittarius', 11,2212UNION All Select 'Capricorn' , 12, 22) Starswhere [Month] * 40 [Day] <= month (@) * 40 day (@)) Endgocreate Function GetStar1 (@ DateTime) Returns VARCHAR (100) asbegin - only SQL Fast - - If there is a static constellation control code table directly in the query, Join efficiency is relatively higher Return (- Declare @ datetime - set @ = getdate () Select max (star) from (- Constellation, the start date of the constellation The Start Date of the Start Day Select 'Capricorn' AS Star, 1 AS [Month], 1 AS [Day] Union All Select 'Aquarius', 1, 20UNION All Select' Pisces', 2, 19Union All Select ' Sheep Rock ', 3, 21UNION All Select' Taurus'
, 4, 20UNION All Select 'Double Subtock', 5,21une All Select 'Cancer', 6,22UNION All Select 'Leo, 7,23uneion All Select' Virgo ', 8,23union All Select' Libra ', 9,23union All Select 'Scorpio', 10, 24Union All Select 'Sagittrah', 11, 22Union All Select 'Capricorn', 12,22) Starswhere Dateadd (day, [day] -1, dateadd (Month, [Month] - 1, Dateadd (Year, Datediff (Year, 0, @), 0))) = (Select Max (Dateadd (DAY, [Day] -1, Dateadd (Month, [Month) -1, Dateadd (Year, Datediff) Year, 0, @), 0)))))) "SELECT 'Capricorn' AS Star, 1 AS [Month], 1 AS [Day] Union All Select 'Aquarius', 1, 20UNION All Select 'Pisces' , 2, 19Union All Select 'Sheep Rock, 3,21une All Select' Golden Block ', 4, 20UNION All Select' Double Subshot ', 5,21une All Select' Cancer ', 6,22UNION All Select' Leo ', 7, 23Union All Select 'Virgo', 8,23union All Select 'Libra', 9, 23Union All Select 'Scorpio', 10, 24UNION All Select 'Sagittraglass', 11, 22UNION All Select 'Capricorn', 12,22) Starswhere @> = dateadd (day, [day] -1, dateadd (Month, [MONTH] -1, Dateadd (Year, Datediff (Year, 0, @), 0))) EndgodeClare @ DateTimeSet @ = getdate )
Select * from starswhere [Month] * 40 [day] = (SELECT MAX (stars. [Month] * 40 stars. [day]) from starswhere stars. [Month] * 40 stars. [day] <= month (@) * 40 day (@)) Gosect C.BIRTHDATE, A.STARFROM Employees Cleft Join Stars Aon Month (C.BIRTHDATE) * 40 Day (C.BIRTHDATE)> = A.MONTH * 40 A.DAYEFT Join Stars Bon A.MONTH * 40 A.DAY Select E.BIRTHDATE, A.STARFROM EMPLOYEES ELEFT JOIN STARFROM EMPLOYEES ELEFT JOIN STARFROM EMPLOYEES ELEFT JOIN STARS AON MONTH (E.BIRTHDATE) * 40 DAY (E.BIRTHDATE)> = A.MONTH * 40 A.DAYLEFT JOIN STARS BON A.MONTH * 40 A. Day