July 30, 2012 at 11:48 pm
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
August 1, 2012 at 3:40 pm
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;
--Vadim R.
August 2, 2012 at 5:35 am
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
August 2, 2012 at 7:58 am
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)
--Vadim R.
August 7, 2012 at 5:32 am
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
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply