Viewing 15 posts - 91 through 105 (of 4,076 total)
The problem is the issue_id. Just remove it from the GROUP BY. I used it in the GROUP BY, because it was in your original query.
Also, if your master_ind is...
September 12, 2023 at 8:02 pm
There are two potential solutions depending on whether the child records have the same category_id and ldk_id as the master record. (NOTE: this is where sample data would be REALLY...
September 12, 2023 at 3:09 pm
This gives you the expected results. You'll probably need to feed the CTE into a MERGE statement to get the updates that you need.
WITH Temp_Changes AS
(
...
September 7, 2023 at 3:42 pm
For best performance, you want to stop using NULL so you don't have to do ISNULL() as part of the WHERE. Yes, you will have to go back and...
August 25, 2023 at 7:44 pm
Your ValidFrom
and ValidUntil
are DATETIME2(7). GETDATE()
returns DATETIME, so you have a mismatch in the precision. Try using SYSDATETIME()
instead of GETDATE()
.
Drew
August 24, 2023 at 5:19 pm
This looks like a Packing Intervals problem. Based on your expected output, I am using closed intervals. That is, both endpoints are considered to be included in the interval, so...
August 24, 2023 at 2:01 pm
Instead of repeatedly saying "two or more tables", I would phrase it as "two row sources". The main benefit of this is to clarify that you are only ever considering...
August 18, 2023 at 5:23 pm
This needs to be done in the presentation layer. SQL queries and stored procedures are the data layer, not the presentation layer. You need to do this in SSRS, Tableau,...
August 15, 2023 at 12:56 pm
Also, many people hesitate to download files from the Internet. You should create expected results in the same way that you created your sample data.
Drew
August 10, 2023 at 3:03 pm
You've made a very common mistake when working with intervals. You're comparing starts with starts and ends with ends. Instead, you should be comparing whether each interval starts before the...
August 10, 2023 at 2:54 pm
Your sample data does not include the value 1900-01-01, yet you expect it in your output. Those rows are missing, because your sample data does not match your expected output. ...
August 8, 2023 at 2:37 pm
This is a very basic attempt to solve your problem. It does not match your expected data, but, as others have pointed out, your expected data may be missing rows. ...
August 8, 2023 at 1:30 pm
Use ROW_NUMBER()
rather than a loop. You would set up your ROW_NUMBER()
so that the latest record is row number 1 and historical records are 2+. If you want more...
August 2, 2023 at 8:30 pm
This is based on code by Itzik Ben-Gan. It uses a cross apply and a sum windowed function to increment the open interval count for start times and decrement it...
July 31, 2023 at 9:00 pm
The subqueries are disastrous for performance. Here is a query that gives the same results (I also added the requested SORT_NBR column) with much better performance.
SELECT b.BASKET_ID
...
July 31, 2023 at 3:16 pm
Viewing 15 posts - 91 through 105 (of 4,076 total)