Get week plus year usind date column in another tabel

  • Hi ,

    I have a table A which i need to include column YearWeek =XXYY

    where XX=right(Year,2),YY=Week ,The Year plus week that date column(it is there in b table) falls in (c table which contains the date for year and week)

    and i need to join b table with c table to get XXYY into my table A.

    how can i insert using insert syntax please help me

    Please correct me if i am wrong

  • your question was missing a lot of things that we'd need to join your two tables together, ket alone insert into one of them.

    give us some more details: the CREATE TABLE scripts are required for a coherent answer.

    as far as getting the year and week as a 4 digit varchar,, here's one way to do it:

    --this returns "1007" note the preceeding zero for week 7

    select RIGHT(YEAR(getdate()),2) + RIGHT('00' + CONVERT(varchar(2),datepart(wk, getdate())),2)

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

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

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