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 1:50 pm
2019 - 1 = 2018, so what wrong with
WHERE sportyear = @year - 1;
here?
With @year being defined as an Integer rather than a datetime.
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
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 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply