• Here's one way to do it in 2005... The neat thing is it doesn't use any RBAR or a sequence table. You could use UPDATE and OUTPUT to return things to the GUI if necessary.

    --===== Create a test table to demonstrate with

    CREATE TABLE DateTest

    (RowNum INT IDENTITY(1,1),

    DateCreated DATETIME)

    --===== Fill it with a bunch of dated rows

    INSERT INTO DateTest

    (DateCreated)

    SELECT DATEADD(hh,t.n-1,'20000101')

    FROM Tally t

    --===== Demo the generation of the required numbers

    SELECT *,

    REPLACE(STR(DATENAME(wk,dt.DateCreated),2) + '-'

    + RIGHT(DATENAME(yy,dt.DateCreated),1),' ','0') + '-'

    + REPLACE(STR(

    ROW_NUMBER() OVER

    (PARTITION BY STR(DATENAME(wk,dt.DateCreated),2)

    + RIGHT(DATENAME(yy,dt.DateCreated),1)

    ORDER BY dt.RowNum),5),' ','0') AS [Wk-Y-NNNNN]

    FROM DateTest dt

    ORDER BY ROWNUM

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)