Temporary Table

  • I have Temporary table with Only One column Year varchar(1000)

    Create table #temp

    (year varchar(1000)

    Year

    2012

    2010

    @UptoMonth = 1 or 2 Or 3

    How can I Update This table with

    2011-@uptomonth-01

    2009 -@uptoMonth-01

    If @uptomonth =1

    then Output

    2011-01-01

    2009-01-01

    I aslo want -1 Year .

    Thanks

    Bhavesh

  • bhaveshp.dba (2/24/2012)


    I have Temporary table with Only One column Year varchar(1000)

    Create table #temp

    (year varchar(1000)

    Year

    2012

    2010

    @UptoMonth = 1 or 2 Or 3

    How can I Update This table with

    2011-@uptomonth-01

    2009 -@uptoMonth-01

    If @uptomonth =1

    then Output

    2011-01-01

    2009-01-01

    I aslo want -1 Year .

    Thanks

    Bhavesh

    First of all, why are you using a varchar(1000) for a column which is no more than 10 characters wide if stored as a string. Is there any reason why you're using characters as opposed to date or datetime?

    I've made the assumption that @uptomonth is a varchar else you'll need to convert it as well

    update #temp

    set [year] = convert(nvarchar(4),convert(int,[year])-1) + '-' +right('0'+@uptomonth,2) + '-01'

  • Thank you so much

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply