How to subtract year from current date and use on where condition of sql server 2000?

Posted by Raghuldrag under Sql Server on 11/20/2014 | Points: 10 | Views : 380 | Status : [Member] | Replies : 1
Hi Friends,
I had a procedure to calculate month variance report , The variance calculated for month with compare to previous year price so made query with input fields @curr_mon_from,@curr_mon_to ,@last_yr_from,@last_yr_to
(here @curr_mon_from,@curr_mon_to these two input fields are current year variance taking month
@last_yr_from,@last_yr_to = these two fields are used to invoke the price of last year )


Now i wanna alter the procedure input fields only two fields i.e @curr_mon_from,@curr_mon_to.
from the input i wanna to subtract the year and take price of last year

ex:

create procedure test_variance
(
@curr_mon_from datetime
,@curr_mon_to datetime
as
begin

get the values for current billed item ,price

select
columns
into
#temp
from
tables
....
....
...
where billdate between @curr_mon_from and
@curr_mon_to


find the last yr price comparision


select
column
into
#temp1
from
table

.....
.....
.....
where dateadd(yy,datediff(yy,0,created_date)-1,0) between @curr_mon_from and
@curr_mon_to

end

its showing error ?

How to do that?
Guide me.




Responses

Posted by: Bandi on: 11/20/2014 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Are you getting syntaxerror/exception or logical error? Can you post the error message if it is any syntax error.

Post the sample data and expected output if it is logical error

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Raghuldrag, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response