I am using SQL Server 2008. I need to pull daily prorated amounts from various tables for custom periods.
For example I need to pull values from March 1, 2018 to April 30, 2019. Some years are leap years and, some are not. So, I would use
SELECT amount / CASE WHEN Year(start_date) % 4 = 0 THEN 366 ELSE 365 END..
Is it possible to declare a variable instead of that CASE statement and I could use it in every query, stored procedure, function, trigger...
SELECT amount / @some_var...
Thank you, Gene
UPDATE: I know that I can not use the formula above for a leap year calculation because the result of it is not always true. This is just an example, sorry, may be not a good one. I am more interested if it is possible to declare some sort of variable, like environment variable in windows, that I can use across queries.