Viewing 15 posts - 16 through 30 (of 76 total)
Good, I couldn't understand why the join was there.
Scott - I would want to log all columns, but only if one or more of the values have changed. An UPDATE...
January 20, 2022 at 5:22 pm
Thanks. The first one is simple and a good starting point for me.
Why in the below is it necessary to join back to tblOrders?
create trigger tblTriggerAuditRecord on...
January 20, 2022 at 4:48 pm
As said above, if possible I would store start and end datetime rather than duration. I've had a similar helpdesk case - you store a calculated duration and then someone...
November 22, 2021 at 7:45 pm
Yes, the two-part method seems to be safer, from Jeff's article. It concludes with recommending an anchor but I couldn't find any examples of this earlier in the article so...
October 25, 2021 at 4:55 pm
Got it working with a version of the Quirky Update, so thanks to Jeff Moden.
Changed it to a temp table rather than table variable and ThisDate is a clustered index....
October 25, 2021 at 3:14 pm
Thanks Ken, for the confirmation that it cannot be done through windowing functions. This post is actually a follow-up to an earlier one I put up - Is loop necessary?...
October 25, 2021 at 8:13 am
You have the input in @T.
The output required is:
'2021-01-01', 100, null, 1
'2021-01-06', 125, 5.00, 1
'2021-01-08', 325, 100.0, 0
'2021-01-16', 155, 3.00, 1
I don't know how I can make it any clearer,...
October 24, 2021 at 6:05 pm
The first three rows output from my attempted query are what I expect.
The last row (2021-01-16) I want to be Usage = 3 and Result = 1. Currently, it is...
October 24, 2021 at 4:50 pm
The scenario is:
Result (Pass or Fail) is a function of Distance, where Distance = N - (N of previous latest Pass)
How can you work out Result for row N without...
October 10, 2021 at 12:52 pm
Many thanks to both of you!
I'd got bogged down in trying to use row_number and dense_rank, and didn't think about using lag.
October 5, 2021 at 3:03 pm
Thanks vliet. It is elegant but having to use a literal value in the windowing frame is a big limitation.
The islands method above also uses six windowing functions - two...
October 8, 2020 at 10:38 am
In my previous attempts, I don't think I can guarantee that RowGroup is unique across the two 'paths', and so could get incorrect result when combined. Would depend on the...
October 5, 2020 at 10:03 am
And without the UNION ALL.
declare @AtLeastCount int = 3
;with T as
(
select *,
RowNum0 = case when Val = 0 then row_number() over(order by ID) else null end,
RowNum1...
October 4, 2020 at 3:23 pm
My solution, no claim to originality.
declare @AtLeastCount int = 3
;with T as
(
select *, RowNum = row_number() over(order by ID)
from @T
),
T1 as
(
select *, RowGroup = RowNum - row_number()...
October 4, 2020 at 11:00 am
Viewing 15 posts - 16 through 30 (of 76 total)