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

How to get current week as 0 for any year using week Expand / Collapse
Author
Message
Posted Monday, July 30, 2012 11:48 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, August 9, 2012 12:33 AM
Points: 21, 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
Post #1337677
Posted Wednesday, August 1, 2012 3:39 PM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Thursday, July 3, 2014 9:59 AM
Points: 990, Visits: 2,217
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;

Post #1338864
Posted Thursday, August 2, 2012 5:35 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

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

Post #1339067
Posted Thursday, August 2, 2012 7:58 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Thursday, July 3, 2014 9:59 AM
Points: 990, Visits: 2,217
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)

Post #1339182
Posted Tuesday, August 7, 2012 5:32 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

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

Add to briefcase

Permissions Expand / Collapse