May 17, 2017 at 7:02 am
koti.raavi - Wednesday, May 17, 2017 6:29 AMyes correct i have mutiple incidents,suppose 123 having 3schedules in a day and 217096 having 2schedules in day..these are jobs used to update data in database
This doesn't really answer the question...
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
May 17, 2017 at 7:38 am
ChrisM@Work - Wednesday, May 17, 2017 7:02 AMkoti.raavi - Wednesday, May 17, 2017 6:29 AMyes correct i have mutiple incidents,suppose 123 having 3schedules in a day and 217096 having 2schedules in day..these are jobs used to update data in databaseThis doesn't really answer the question...
if possible provide query for latest data I have provided that would be great, thanks
May 17, 2017 at 7:55 am
koti.raavi - Wednesday, May 17, 2017 7:38 AMChrisM@Work - Wednesday, May 17, 2017 7:02 AMkoti.raavi - Wednesday, May 17, 2017 6:29 AMyes correct i have mutiple incidents,suppose 123 having 3schedules in a day and 217096 having 2schedules in day..these are jobs used to update data in databaseThis doesn't really answer the question...
if possible provide query for latest data I have provided that would be great, thanks
No problemSELECT *, dr = CASE WHEN Failure = 1 THEN DENSE_RANK() OVER(PARTITION BY IncidentID, Grp ORDER BY File_Date) ELSE 0 END
FROM (
SELECT *, Grp = rn1-rn2
FROM (
SELECT *,
rn1 = ROW_NUMBER() OVER(PARTITION BY IncidentID ORDER BY File_Date, ScheduleTime),
rn2 = ROW_NUMBER() OVER(PARTITION BY IncidentID, Failure ORDER BY File_Date, ScheduleTime)
FROM #test t
CROSS APPLY (SELECT Failure = CASE WHEN ExecutedTime > '00:00:00.0000000' THEN 0 ELSE 1 END) x
) d1
) d2
ORDER BY File_Date, ScheduleTime
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
May 17, 2017 at 8:20 am
ChrisM@Work - Wednesday, May 17, 2017 7:55 AMkoti.raavi - Wednesday, May 17, 2017 7:38 AMChrisM@Work - Wednesday, May 17, 2017 7:02 AMkoti.raavi - Wednesday, May 17, 2017 6:29 AMyes correct i have mutiple incidents,suppose 123 having 3schedules in a day and 217096 having 2schedules in day..these are jobs used to update data in databaseThis doesn't really answer the question...
if possible provide query for latest data I have provided that would be great, thanks
No problem
SELECT *, dr = CASE WHEN Failure = 1 THEN DENSE_RANK() OVER(PARTITION BY IncidentID, Grp ORDER BY File_Date) ELSE 0 END
FROM (
SELECT *, Grp = rn1-rn2
FROM (
SELECT *,
rn1 = ROW_NUMBER() OVER(PARTITION BY IncidentID ORDER BY File_Date, ScheduleTime),
rn2 = ROW_NUMBER() OVER(PARTITION BY IncidentID, Failure ORDER BY File_Date, ScheduleTime)
FROM #test t
CROSS APPLY (SELECT Failure = CASE WHEN ExecutedTime > '00:00:00.0000000' THEN 0 ELSE 1 END) x
) d1
) d2
ORDER BY File_Date, ScheduleTime
it looks good but having one issue, please run below update statement
UPDATE A
SET ExecutedTime='00:00:00.0000000'
From #Test A Where File_date='2017-04-28'
For 2017-04-28 date and schedule 17:00:00:00 having aging 2 but it should have one.
the reason for 1 is it is successfully executed on 2017-04-28 (17:00:00:00). Thank you Chris.
I have attached pic for this.
May 17, 2017 at 8:31 am
koti.raavi - Wednesday, May 17, 2017 8:20 AMChrisM@Work - Wednesday, May 17, 2017 7:55 AMkoti.raavi - Wednesday, May 17, 2017 7:38 AMChrisM@Work - Wednesday, May 17, 2017 7:02 AMkoti.raavi - Wednesday, May 17, 2017 6:29 AMyes correct i have mutiple incidents,suppose 123 having 3schedules in a day and 217096 having 2schedules in day..these are jobs used to update data in databaseThis doesn't really answer the question...
if possible provide query for latest data I have provided that would be great, thanks
No problem
SELECT *, dr = CASE WHEN Failure = 1 THEN DENSE_RANK() OVER(PARTITION BY IncidentID, Grp ORDER BY File_Date) ELSE 0 END
FROM (
SELECT *, Grp = rn1-rn2
FROM (
SELECT *,
rn1 = ROW_NUMBER() OVER(PARTITION BY IncidentID ORDER BY File_Date, ScheduleTime),
rn2 = ROW_NUMBER() OVER(PARTITION BY IncidentID, Failure ORDER BY File_Date, ScheduleTime)
FROM #test t
CROSS APPLY (SELECT Failure = CASE WHEN ExecutedTime > '00:00:00.0000000' THEN 0 ELSE 1 END) x
) d1
) d2
ORDER BY File_Date, ScheduleTimeit looks good but having one issue, please run below update statement
UPDATE A
SET ExecutedTime='00:00:00.0000000'
From #Test A Where File_date='2017-04-28'
For 2017-04-28 date and schedule 17:00:00:00 having aging 2 but it should have one.
the reason for 1 is it is successfully executed on 2017-04-28 (17:00:00:00). Thank you Chris.
I have attached pic for this.
Please compare the logic of your update statement with "it is successfully executed on 2017-04-28".
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
May 17, 2017 at 8:43 am
Apologies,
For 2017-04-27 date having two schedules that is 17:00 and 23:00 , 17:00 is executed successfully - result is 0 and 23:00 is not executed- result is 1
For 2017-04-28 schedule 17:00 is not executed the result should be 1 but it showing as "2" after running update statement provided above, hope this helps! thanks!
May 17, 2017 at 8:48 am
koti.raavi - Wednesday, May 17, 2017 8:43 AMApologies,
For 2017-04-27 date having two schedules that is 17:00 and 23:00 , 17:00 is executed successfully - result is 0 and 23:00 is not executed- result is 1
For 2017-04-28 schedule 17:00 is not executed the result should be 1 but it showing as "2" after running update statement provided above, hope this helps! thanks!
It looks consistent and correct to me:
217096 2017-04-27 23:00:00.0000000 00:00:00.0000000 1 1 52 39 13 1
217096 2017-04-28 17:00:00.0000000 00:00:00.0000000 0 1 53 40 13 2
217096 2017-04-28 23:00:00.0000000 00:00:00.0000000 0 1 54 41 13 2
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
May 17, 2017 at 9:41 am
Nope,why last column data is number 2 for 17:00:00.000000 schedule on 2017-04-28 it should be number 1 beacause it is successfully on 2017-04-27 for 17:00:00.00000 schedule,thanks
May 17, 2017 at 9:44 am
koti.raavi - Wednesday, May 17, 2017 9:41 AMNope,why last column data is number 2 for 17:00:00.000000 schedule on 2017-04-28 it should be number 1 beacause it is successfully on 2017-04-27 for 17:00:00.00000 schedule,thanks
Why is the rule different for this specific data point? It contradicts the rules for the previous group - increment the number on each new day.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
May 17, 2017 at 9:54 am
sorry looks like some confusion, rule is same ,the code is fine for incident having one schedule
but the problem with multiple schedule , when im using query for real data im finding more scenarios,sorry for trouble.Thanks
May 17, 2017 at 9:57 am
koti.raavi - Wednesday, May 17, 2017 9:54 AMsorry looks like some confusion, rule is same ,the code is fine for incident having one schedulebut the problem with multiple schedule , when im using query for real data im finding more scenarios,sorry for trouble.Thanks
Change your sample data to reflect your observations with the real data, and I'll be able to help.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
May 17, 2017 at 10:22 am
koti.raavi - Wednesday, May 17, 2017 9:41 AMNope,why last column data is number 2 for 17:00:00.000000 schedule on 2017-04-28 it should be number 1 beacause it is successfully on 2017-04-27 for 17:00:00.00000 schedule,thanks
late to this thread...and kudos to Chris for his patience.
is this the result set you are looking for?+--------+------------+------------------+------------------+---+---+----+----+----+---+
| 217096 | 2017-04-27 | 17:00:00.0000000 | 17:04:54.0000000 | 0 | 0 | 26 | 7 | 19 | 0 |
| 217096 | 2017-04-27 | 23:00:00.0000000 | 00:00:00.0000000 | 1 | 1 | 26 | 20 | 6 | 1 |
| 217096 | 2017-04-28 | 17:00:00.0000000 | 00:00:00.0000000 | 0 | 1 | 27 | 20 | 7 | 1 |
| 217096 | 2017-04-28 | 23:00:00.0000000 | 00:00:00.0000000 | 0 | 1 | 27 | 21 | 6 | 2 |
| 217096 | 2017-04-29 | 17:00:00.0000000 | 17:00:16.0000000 | 0 | 0 | 28 | 8 | 20 | 0 |
+--------+------------+------------------+------------------+---+---+----+----+----+---+
________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day
May 17, 2017 at 10:37 am
Yes correct Livingston, you and chris are masters,kudos to both of you. thanks for your time to read all chat content.????
May 17, 2017 at 10:44 am
koti.raavi - Wednesday, May 17, 2017 10:37 AMYes correct Livingston, you and chris are masters,kudos to both of you. thanks for your time to read all chat content.👌👌
a small amendment to Chris's code will deliver then....unless you add other requirements !
SELECT *, dr = CASE WHEN Failure = 1 THEN DENSE_RANK() OVER(PARTITION BY IncidentID, Grp ORDER BY File_Date) ELSE 0 END
FROM (
SELECT *, Grp = rn1-rn2
FROM (
SELECT *,
rn1 = ROW_NUMBER() OVER(PARTITION BY IncidentID, ScheduleTime ORDER BY File_Date ),
rn2 = ROW_NUMBER() OVER(PARTITION BY IncidentID, ScheduleTime, Failure ORDER BY File_Date)
FROM #test t
CROSS APPLY (SELECT Failure = CASE WHEN ExecutedTime > '00:00:00.0000000' THEN 0 ELSE 1 END) x
) d1
) d2
ORDER BY File_Date, ScheduleTime
________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day
May 18, 2017 at 1:43 am
J Livingston SQL - Wednesday, May 17, 2017 10:44 AMkoti.raavi - Wednesday, May 17, 2017 10:37 AMYes correct Livingston, you and chris are masters,kudos to both of you. thanks for your time to read all chat content.👌👌a small amendment to Chris's code will deliver then....unless you add other requirements !
SELECT *, dr = CASE WHEN Failure = 1 THEN DENSE_RANK() OVER(PARTITION BY IncidentID, Grp ORDER BY File_Date) ELSE 0 END
FROM (
SELECT *, Grp = rn1-rn2
FROM (
SELECT *,
rn1 = ROW_NUMBER() OVER(PARTITION BY IncidentID, ScheduleTime ORDER BY File_Date ),
rn2 = ROW_NUMBER() OVER(PARTITION BY IncidentID, ScheduleTime, Failure ORDER BY File_Date)
FROM #test t
CROSS APPLY (SELECT Failure = CASE WHEN ExecutedTime > '00:00:00.0000000' THEN 0 ELSE 1 END) x
) d1
) d2
ORDER BY File_Date, ScheduleTime
Nice catch G!
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Viewing 15 posts - 16 through 29 (of 29 total)
You must be logged in to reply to this topic. Login to reply