How can i make auto number from the first day of the year?

  • How can i make auto number from the first day of the year?

    How can I make this?

    From the binging of the year

    In the date of

    01/01/2004         I wont that the number will bee

    1-2004   And  after. 2-2004 .. 3-2004 ……………………………….. 99-2004

    AND until the end of the year  of 2004

     

    AND in the beginning of the year 2005 from the date

      01/01/2005

    The number will start from the number 1-2005  and after 2-2005 ………. 99-2005

    And I wont every year in the beginning of the year the number will  start from

    1

    Tanks

    ilan

  • SELECT convert(varchar(3), DATEDIFF ( day , '01/01/2004' , getdate())) + '-' + convert(varchar(4), YEAR(getdate()))

  • And what abut the auto number from the beginning of the year that  

    I wont that the number start from 1

    until the end of the year  !!!

    And start in the next year from 1  

    until the end of the year  !!!

    thaks

    ilan

     

  • And what abut the auto number from the beginning of the year that  

    I wont that the number start from 1

    until the end of the year  !!!

    And start in the next year from 1  

    until the end of the year  !!!

    thaks

    ilan

     

  • Check the answer from your another posting "new year new number Generating in SQL server"



    Regards,
    kokyan

  • SELECT convert(varchar(3), DATEDIFF ( day , '01/Jan/'+ltrim(str(year(getdate()))) , getdate())) + '-' + convert(varchar(4), YEAR(getdate()))

    This Will Solve the Problem, remember very first number will be zero. 

     

    Manish

     

     

  • SQL Server can provide the values you want using  DatePart ( dy, <date> ).

    Try these examples:

    declare @date datetime

    set @date = '1/1/2003'

    SELECT Convert(varchar(3), DatePart(dy, @date)) + '-' + Convert(varchar(4), Year(@date))

    set @date = '1/2/2003'

    SELECT Convert(varchar(3), DatePart(dy, @date)) + '-' + Convert(varchar(4), Year(@date))

    set @date = '12/31/2003'

    SELECT Convert(varchar(3), DatePart(dy, @date)) + '-' + Convert(varchar(4), Year(@date))

    set @date = '1/1/2004'

    SELECT Convert(varchar(3), DatePart(dy, @date)) + '-' + Convert(varchar(4), Year(@date))

    Mike

  • Just noticed. Please do not cross post. Related thread http://qa.sqlservercentral.com/forums/shwmessage.aspx?forumid=8&messageid=99652

Viewing 8 posts - 1 through 7 (of 7 total)

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