SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to display current week as 0 for each year


How to display current week as 0 for each year

Author
Message
84gopi
84gopi
SSC Rookie
SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)

Group: General Forum Members
Points: 41 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
Karthiart
Karthiart
Valued Member
Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)

Group: General Forum Members
Points: 54 Visits: 186
Please provide the ddl for your requirement. (Table structure & sample values)

Regards,
Karthik.
SQL Developer.
Lowell
Lowell
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28076 Visits: 39926
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!

84gopi
84gopi
SSC Rookie
SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)

Group: General Forum Members
Points: 41 Visits: 60
Hi,

PFA doc of my report requirement.

Thanks
Gopi
Attachments
report req.doc (15 views, 66.00 KB)
Lowell
Lowell
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28076 Visits: 39926
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!

84gopi
84gopi
SSC Rookie
SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)

Group: General Forum Members
Points: 41 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
Lowell
Lowell
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28076 Visits: 39926
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!

84gopi
84gopi
SSC Rookie
SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)

Group: General Forum Members
Points: 41 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
Attachments
data sample.doc (5 views, 62.00 KB)
Lowell
Lowell
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28076 Visits: 39926
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!

84gopi
84gopi
SSC Rookie
SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)

Group: General Forum Members
Points: 41 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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search