Viewing 11 posts - 16 through 26 (of 26 total)
Okay ... a better example.
I am a police supervisor wondering how many crimes are committed during my officers shifts:
Officer
---------
OfficerID
ShiftID
ShiftStart
ShiftEnd
Crime
------
CrimeID
CrimeDate
SELECT
OfficerID,
ShiftStart,
ShiftEnd,
COUNT(CrimeID)
FROM
Officer o
INNER JOIN Crime c ON o.ShiftStart <= i.CrimeDate AND o.ShiftEnd >=...
September 26, 2013 at 2:51 pm
Don't listen to RBAR-phobes ... there are plenty of valid uses for a comparison operator in a SQL Join.
Bad = using it to make 1,000,000's of Cartesian products to filter...
September 26, 2013 at 12:14 pm
I get a different random number every time I reference the CTE ?!?!
SELECT l1.ticketID, l1.iRandom, l2.iRandom FROM lottery l1 INNER JOIN lottery l2 ON l1.TicketID = l2.TicketID
Well, I guess...
September 24, 2013 at 2:10 pm
This ugly bit of code gets me frighteningly close ...
SELECT
t1.AcctID, t1.iOrder, t1.ilevel,
/* The second level is always the parent folder of the detail */
t2.AcctID Level2ID, t2.iOrder Level2Order,
CASE WHEN t1.iLevel...
September 17, 2013 at 2:13 pm
Jeff Moden (9/17/2013)[/b
Heh... you need to ignore those "multiple sources" because they're condeming one of the easier methods to maintain hierarchical data there is.
Well, one of those sources (and the...
September 17, 2013 at 1:58 pm
Eliza (9/16/2013)
All the information for parameters comes from three tables. All joined with inner joins.
At the moment I feel I have functions embedded with functions and its not clean...
September 17, 2013 at 10:42 am
Start with my code for finding "CTEMissingDates" ... but add a group ID for your groups (1,2, etc)
At that point you can group them into ranges using the technique from...
September 13, 2013 at 3:35 pm
I'm not sure where your expected data for "2" is coming from ... but you should be able to expand this if necessary to groups
This is quick and dirty but...
September 13, 2013 at 11:04 am
I definitely agree that without knowing the scope of PCC's business requirement for aligning the "Cham" field across days, we can not present an optimal solution.
I guess the way I...
August 29, 2013 at 10:18 am
Your solution would run much faster (my code must test every previous day in order to determine the proper sort order, and you rely on a case statement) but I...
August 28, 2013 at 10:34 am
Piece of cake ... you can make it a lot more concise but this explains it easier:
WITH agg AS
(SELECT
DueDate,
ROW_NUMBER() OVER (ORDER BY DueDate) AS iRow,
SUM(CASE WHEN Cham...
August 27, 2013 at 4:10 pm
Viewing 11 posts - 16 through 26 (of 26 total)