June 14, 2019 at 7:24 am
Hi,
I am passing parameter in my store procedure.
declare @year datetime= '2019'
select * from table where sportyear=@year
How can I extract where if i pass in '2019', my where condition sportyear will get last year which is 2018.
June 14, 2019 at 8:17 am
Hi, I am passing parameter in my store procedure. declare @year datetime= '2019' select * from table where sportyear=@year How can I extract where if i pass in '2019', my where condition sportyear will get last year which is 2018.
What is the datatype of sportyear in the table?
If it is datetime, then your select will only bring back results where sportyear = '2019-01-01 00:00:00.000'. Any other values in the year will be filtered out
June 14, 2019 at 2:11 pm
select * from table where sportyear=DATEADD(YEAR, -1, @year)
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy