Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

How to display current week as 0 for each year Expand / Collapse
Author
Message
Posted Wednesday, August 1, 2012 3:20 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, August 9, 2012 12:33 AM
Points: 21, Visits: 60
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
Post #1338387
Posted Wednesday, August 1, 2012 5:22 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, August 4, 2014 5:46 AM
Points: 33, Visits: 156
Please provide the ddl for your requirement. (Table structure & sample values)

Regards,
Karthik.
SQL Developer.
Post #1338430
Posted Wednesday, August 1, 2012 7:25 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 4:43 AM
Points: 12,895, Visits: 32,090
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1338510
Posted Wednesday, August 1, 2012 7:26 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, August 9, 2012 12:33 AM
Points: 21, Visits: 60
Hi,

PFA doc of my report requirement.

Thanks
Gopi


  Post Attachments 
report req.doc (11 views, 66.00 KB)
Post #1338511
Posted Wednesday, August 1, 2012 7:30 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 4:43 AM
Points: 12,895, Visits: 32,090
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1338516
Posted Wednesday, August 1, 2012 7:38 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, August 9, 2012 12:33 AM
Points: 21, Visits: 60
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
Post #1338528
Posted Wednesday, August 1, 2012 7:41 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 4:43 AM
Points: 12,895, Visits: 32,090
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1338535
Posted Thursday, August 2, 2012 12:21 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, August 9, 2012 12:33 AM
Points: 21, Visits: 60
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


  Post Attachments 
data sample.doc (3 views, 62.50 KB)
Post #1338963
Posted Thursday, August 2, 2012 5:46 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 4:43 AM
Points: 12,895, Visits: 32,090
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1339072
Posted Thursday, August 2, 2012 7:40 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, August 9, 2012 12:33 AM
Points: 21, Visits: 60
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
Post #1339161
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse