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

Tally Calendars and 'Week 1' Expand / Collapse
Author
Message
Posted Tuesday, January 8, 2013 1:56 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Tuesday, October 7, 2014 10:53 PM
Points: 3,421, Visits: 5,359
Jason-299789 (1/8/2013)
Final Edit,

Dwain, I figured out why yours didnt work you're addind on the Julian day which is 1-365/366

I think you need to add the Week day number something like this

CREATE TABLE #Calendar
([Date] DATETIME PRIMARY KEY
,[Year] INT
,[JulWk] INT
,[WkDNo] INT
,ISO_WK AS (CAST([Year] AS CHAR(4)) + 'W' +
CAST([JulWk] AS VARCHAR(2)) + '-' +
CAST([WkDNo] AS VARCHAR(3)))
)

INSERT INTO #Calendar
SELECT [Date], [Year], [JulWk], [WkDNo]
FROM GenerateCalendar('20120101', 365*2)

SELECT * FROM #Calendar
WHERE ISO_WK LIKE '2012W26-[67]'




Ah-ha! Indeed that does seem to fix it. Thought Joe meant Julian day not week day number.



My mantra: No loops! No CURSORs! No RBAR! Hoo-uh!

My thought question: Have you ever been told that your query runs too fast?

My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.


Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Learn to understand recursive CTEs by example.
Splitting strings based on patterns can be fast!
Post #1404053
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse