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.
If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.
June 14, 2019 at 2:11 pm
select * from table where sportyear=DATEADD(YEAR, -1, @year)
SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply