Viewing 15 posts - 2,446 through 2,460 (of 4,087 total)
Sorry, I didn't realize that you were on SQL 2005. You need SQL 2012 to use this construct. I should pay more attention to which forum I'm in.
Drew
August 18, 2016 at 2:53 pm
ChrisM@Work (8/18/2016)
-- set up some data to code againstDROP TABLE #MyTable
SELECT *
INTO #MyTable
FROM (
SELECT 123, 1 UNION ALL
SELECT 456, 2 UNION ALL
SELECT 789, 1 UNION ALL
SELECT 789, 2 UNION ALL
SELECT...
August 18, 2016 at 11:21 am
This non-recursive CTE works with pre-aggregated (and mixed) data.
;
WITH running_total AS (
SELECT *, SUM(mt.copies) OVER(ORDER BY mt.subscriberid , mt.copies ROWS UNBOUNDED PRECEDING) AS rt
FROM #MyTable mt
)
SELECT rt.subscriberid,
CASE
WHEN rt.rt <= @num_records...
August 18, 2016 at 11:14 am
Are you aggregating your data in your query or is it pre-aggregated? That is, do you have two records for 456 and three records for 789, or do you...
August 18, 2016 at 10:37 am
DesNorton (8/17/2016)
Unless my understanding is incorrect, I believe that the movement in this solution is the wrong way around.
To prove this, let's take a look at only the first movement...
August 18, 2016 at 8:40 am
I'm writing an article explaining my solution to Credits and Debits and am looking for two or three people to review it before I submit it. Any takers?
Drew
August 17, 2016 at 12:06 pm
I realized this morning that my code needed a slight update. My updates sample data had the same ordering for the from_seq and the to_seq, but that is not...
August 17, 2016 at 9:32 am
Here is a version that allows you to update multiple records at the same time.
DECLARE @A TABLE (
seqINT,
orig_seq INT
)
INSERT @A( seq, orig_seq)
VALUES(1, 1), (2, 2), (3, 3), (4, 4), (5,...
August 16, 2016 at 2:42 pm
Code that you get on the Internet should never be considered a complete solution. It's impossible to cover every single scenario in a small sample of data. That's...
August 16, 2016 at 8:47 am
John Mitchell-245523 (8/15/2016)
August 15, 2016 at 12:25 pm
jssashank (8/15/2016)
drew.allen (8/12/2016)
August 15, 2016 at 11:56 am
John Mitchell-245523 (8/15/2016)
Now, if the join were an outer (instead of...
August 15, 2016 at 9:08 am
Except for the fact that I was selecting the Transaction ID rather than the credit ID, my query produces the exact results that you say you are expecting. Perhaps...
August 12, 2016 at 10:36 pm
Okay. I think I figured out where the problem is. I also realized that I didn't need one of the clauses in one of the CASE statements, so...
August 12, 2016 at 2:53 pm
jssashank (8/12/2016)
drew.allen (8/11/2016)
;
WITH totals AS (
SELECT *, ABS(Amount) AS Amt, SUM(ABS(Amount)) OVER(PARTITION BY Customer, TransactionType ORDER BY Date ROWS UNBOUNDED...
August 12, 2016 at 2:09 pm
Viewing 15 posts - 2,446 through 2,460 (of 4,087 total)