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


How to get current week as 0 for any year using week


How to get current week as 0 for any year using week

Author
Message
84gopi
84gopi
Valued Member
Valued Member (59 reputation)Valued Member (59 reputation)Valued Member (59 reputation)Valued Member (59 reputation)Valued Member (59 reputation)Valued Member (59 reputation)Valued Member (59 reputation)Valued Member (59 reputation)

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

I need to display current week as 0 for any year in the report......using week column in week table.

I have week values like wk1,wk2.....wk53 for 3 years from 2009 to 2011.........

I need to display current week as 0 irrespective of any year if user selects.......

Can any one provide the sql function for this......

Thanks
Gopi
rVadim
rVadim
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1413 Visits: 2308

CREATE TABLE #WeekTable(
YearCol INT
,WeekCol VARCHAR(9)
);

INSERT INTO #WeekTable (YearCol, WeekCol)
SELECT 2009, 'wk1' UNION ALL
SELECT 2009, 'wk31' UNION ALL
SELECT 2009, 'wk52' UNION ALL
SELECT 2010, 'wk1' UNION ALL
SELECT 2010, 'wk31' UNION ALL
SELECT 2010, 'wk52' UNION ALL
SELECT 2011, 'wk1' UNION ALL
SELECT 2011, 'wk31' UNION ALL
SELECT 2011, 'wk52'

SELECT
[Week] = CASE WHEN REPLACE(WeekCol, 'wk', '') = DATEPART(wk, CURRENT_TIMESTAMP)
THEN '0'
ELSE WeekCol
END
,*
FROM #WeekTable;

DROP TABLE #WeekTable;


84gopi
84gopi
Valued Member
Valued Member (59 reputation)Valued Member (59 reputation)Valued Member (59 reputation)Valued Member (59 reputation)Valued Member (59 reputation)Valued Member (59 reputation)Valued Member (59 reputation)Valued Member (59 reputation)

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

Thanks for the details but I don't have access to run these commands in our db. I can access from report end....

Means I need to use whatever tables already there in my package as I told you earlier.....I need to use Merchandise week table from my package which is having values like wk1,wk2.....wk53 for each year..

Only thing I can do is use the fucntions which is there in report level like date functions or case,if,for anything to get our output.

Thanks
Gopi
rVadim
rVadim
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1413 Visits: 2308
You posted your question in SQL Server Development forum and you asked for sql function...

What report are you talking about? If this is SSRS report the VB.Net also has DatePart function you can use.

http://msdn.microsoft.com/en-us/library/20ee97hz(v=vs.71).aspx

=DatePart(DateInterval.WeekOfYear, Today)


84gopi
84gopi
Valued Member
Valued Member (59 reputation)Valued Member (59 reputation)Valued Member (59 reputation)Valued Member (59 reputation)Valued Member (59 reputation)Valued Member (59 reputation)Valued Member (59 reputation)Valued Member (59 reputation)

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

I can't execue these cmsds in our database since I don't have rights to do that. I was talking about the Cognos Reports where I have to implement this logic to run my report.

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