Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need syntax for 1 year prior the given date

Status
Not open for further replies.

teddysnow12

Programmer
Aug 12, 2011
30
US
Hi,

I need a syntax which gives 1 year prior to a given year .

My field is rptg_yyyymm.
the datatype is string.

example : The values are like this,

'2008-01'
'2008-02'

I should convert this into date format and also need syntax for 1year prior this date like,

if the given year is 2008-01,
the prior year is 2007-01



Thanks!
 
convert(varchar(4),convert(int,substring(rptg_yyyymm,1,4))-1) + '-' + SUBSTRING(rptg_yyyymm,6,2)
 
thank you for you response.
but it is throwing an error saying ' Missing expresssion' and pointing at varchar
 
please post the sql (context) in which you are using it.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top