Seasonal Returning Function in SQL Server
Hello to everyone,
In this article, I will give information about the function that brings seasonal information in SQL Server.
In SQL Server you may want to fetch seasonal information in some cases.
You can easily do this with the help of the function below.
CREATE FUNCTION getSeasonInformation
(
@Date DATETIME
)
RETURNS VARCHAR(20)
BEGIN
RETURN (CASE
WHEN MONTH(@Date) IN ( 12, 1, 2 ) THEN
'Winter'
WHEN MONTH(@Date) IN ( 3, 4, 5 ) THEN
'Spring'
WHEN MONTH(@Date) IN ( 6, 7, 8 ) THEN
'Summer'
WHEN MONTH(@Date) IN ( 9, 10, 11 ) THEN
'Autumn'
END
);
END;
--Kullanımı
SELECT dbo.getSeasonInformation(GETDATE()) AS SeasonInformation
When you create the function and run the code, you will get a result like the one below.
As you can see, the information on which season we are in is based on the entered date.
Good luck to everyone in business and life.