How to display current week as 0 for each year

  • Hi,

    I have a report requirement where I need to display current week as 0 for any season year user selects....like Spring,Fall,Summer & winter seaon from 2009 to 2012....

    Ex: If user selects Spring 2009 as season then it should display week in 1st row & corresponding month-year in next row.....these 2 rows I am getting already in the report......

    But i am having issue in getting current week as 0....I tried with datapart & date functions....but i didn't get the output.

    Please help me to write sql function for above logic........

    I have week column in my table having values like wk1,wk2.....wk53 for each year........

    Thanks

    Gopi

  • Please provide the ddl for your requirement. (Table structure & sample values)

    Regards,
    Karthik.
    SQL Developer.

  • 84gopi all 14 of your posts over the last 20 days are on the same subject: showing your data by weeks and ranges of weeks, in what i think is a cross tab format.

    Sample Data has been requested in more than half of those posts (that means a CREATE TABLE statement, INSERT INTO statements showing example data)

    but you never provided it.

    There's a lot of "best guess" posts and examples some of our volunteers, including myself have thrown out there, but instead of following up on those examples, and clarifying with your real DDL/sample data, you create new posts instead.

    Help us help you! stick with one of those posts you feel you can understand or need additional explanations on.

    take the time to right click the table in your database and script it, and create a few rows of sample data.

    only with that will you get a solid, tested, workable example.

    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!

  • Hi,

    PFA doc of my report requirement.

    Thanks

    Gopi

  • 84gopi (8/1/2012)


    Hi,

    PFA doc of my report requirement.

    Thanks

    Gopi

    good, you are one third of the way there!

    1. CREATE TABLE stuff: missing...

    2. INSERT INTO stuff...missing.

    3. xpected Output...attached.

    a word doc or screenshots is not a substitute for the CREATE TABLE...INSERT INTO.

    it does help as far as the expected output, however.

    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!

  • Hi,

    I have merchandise week table in my package which contains week values wk1,wk2,wk3.....upto wk53 per year.

    So using this i need to display current week as 0, for any season like spring2009 or fall2009 etc.......

    Let me know if you need more details.....

    Thanks

    Gopi

  • 84gopi (8/1/2012)


    Hi,

    I have merchandise week table in my package which contains week values wk1,wk2,wk3.....upto wk53 per year.

    So using this i need to display current week as 0, for any season like spring2009 or fall2009 etc.......

    Let me know if you need more details.....

    Thanks

    Gopi

    athe details i need are the CREATE TABLE YourMerchandiseTable...

    and some INSERT INTO example rows.

    please don't copy and paste the same info over and over again...i know there is a language barrier problem, but please try.

    something like this?

    CREATE TABLE [dbo].[MYMERCHANDISE] (

    [ID] INT NULL,

    [SALEDATE] DATETIME NULL,

    [DESCRIP] VARCHAR(30) NULL)

    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!

  • Hi,

    Here is the merchandise week table structure details from our database

    create table dbo.T_AGGR_MERCHANDISING_WEEK_DIM

    (MERCHANDISING_WEEK_DIM_ID pk,int,not null,

    MERCHANDISING_WEEK char(4),not null,

    MERCHANDISING_YEAR char(4), not null

    MERCHANDISING_WEEK_START_DATE datetime,not null

    MERCHANDISING_WEEK_END_DATE datetime,not null)

    PFA doc for the values for above table......

    Thanks

    Gopi

  • so close...we have a table now, and some expected results....but you provided screenshots of data.

    i cannot copy paste those screenshots into SSMS to get the sample data.

    I'm looking for commands like this, that any of the volunteers can use to get the structure of the table and the data so we can test:

    --The required CREATE TABLE

    CREATE TABLE [dbo].[T_AGGR_MERCHANDISING_WEEK_DIM] (

    [MERCHANDISING_WEEK_DIM_ID] INT NOT NULL,

    [MERCHANDISING_WEEK] CHAR(4) NOT NULL,

    [MERCHANDISING_YEAR] CHAR(4) NOT NULL,

    [MERCHANDISING_WEEK_START_DATE] DATETIME NOT NULL,

    [MERCHANDISING_WEEK_END_DATE] DATETIME NOT NULL,

    CONSTRAINT [PK__T_AGGR_M__BC8A2AD00A537D18] PRIMARY KEY CLUSTERED (MERCHANDISING_WEEK_DIM_ID))

    --SOME fake but representitive of the issue DATA I created.

    INSERT INTO [T_AGGR_MERCHANDISING_WEEK_DIM]([MERCHANDISING_WEEK],[MERCHANDISING_YEAR],[MERCHANDISING_WEEK_START_DATE],[MERCHANDISING_WEEK_END_DATE])

    SELECT 1,'WK1','2009','2009-01-01 00:00:00.000' UNION ALL

    SELECT 2,'WK2','2009','2009-01-04 00:00:00.000' UNION ALL

    SELECT 2,'WK2','2009','2009-01-11 00:00:00.000'

    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!

  • Hi,

    If I give you starting 5 to 10 rows of the merchandise week table stmts is that enough to test?

    Something like below.........

    insert into dbo.T_AGGR_MERCHANDISING_WEEK_DIM(MERCHANDISING_WEEK_DIM_ID,MERCHANDISING_WEEK,MERCHANDISING_YEAR,

    MERCHANDISING_WEEK_START_DATE,MERCHANDISING_WEEK_END_DATE)

    values (186,'wk27',2012,2012-07-01 00:00:00:000,2012-07-07 00:00:00:000),

    values (187,'wk28',2012,2012-07-08 00:00:00:000,2012-07-14 00:00:00:000),

    values (188,'wk29',2012,2012-07-15 00:00:00:000,2012-07-21 00:00:00:000),

    values (189,'wk30',2012,2012-07-22 00:00:00:000,2012-07-28 00:00:00:000),

    values (190,'wk31',2012,2012-07-29 00:00:00:000,2012-08-04 00:00:00:000),

    values (191,'wk32',2012,2012-08-05 00:00:00:000,2012-08-11 00:00:00:000),

    values (192,'wk33',2012,2012-08-12 00:00:00:000,2012-08-18 00:00:00:000),

    values (193,'wk34',2012,2012-08-19 00:00:00:000,2012-08-25 00:00:00:000),

    Thanks

    Gopi

  • Hi,

    I didn't get any response to my reply? do any one need mpre details?

    Thanks

    Gopi

  • as an idea....is this anywhere close to what you are looking for?

    SELECT MERCHANDISING_WEEK_START_DATE ,

    DATEPART( WEEK , MERCHANDISING_WEEK_START_DATE ) - DATEPART( WEEK , GETDATE( ))

    FROM T_AGGR_MERCHANDISING_WEEK_DIM;

    ________________________________________________________________
    you can lead a user to data....but you cannot make them think
    and remember....every day is a school day

Viewing 12 posts - 1 through 11 (of 11 total)

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