Viewing 15 posts - 31 through 45 (of 4,033 total)
Generally, an approach that uses windowed functions is going to perform better than one using CROSS/OUTER APPLY, because it's going to have to read the table fewer times. The following...
October 18, 2023 at 4:19 pm
This gives the same results as Ken's query. (NOTE: I changed your permanent table to a temp table.)
WITH InOutStatuses AS
(
SELECT ts.GroupingId, i.InOutDate, SUM(i.InOutStatus)...
October 17, 2023 at 2:33 pm
This produces the same results as Phil's. I made some assumptions that may not be warranted.
October 16, 2023 at 8:25 pm
This gives your expected results. I partitioned and joined on the Sponsor, Pharmacy, and Drug. You may need to change this.
WITH RunningTotals AS
(
SELECT...
October 12, 2023 at 8:07 pm
It doesn't appear that you've tried to incorporate the techniques that you've already been given. Your latest post only has minor differences from your first post in this thread. You...
October 12, 2023 at 5:09 pm
I think you just need to add a partition to your ROW_NUMBER()
.
SELECT * FROM
(
SELECT YEAR(OrderDate) AS OrderYear,
...
October 12, 2023 at 2:45 pm
This seems to give your expected results despite not referring to the "dis" column at all.
WITH test_resets AS
(
SELECT *, SUM(CASE WHEN ompt...
October 12, 2023 at 2:20 pm
Thanks for your feedback Phil,
The reason for the layout of my sample data was just for simplicity. I inserted my sample data into a physical table and then just...
October 11, 2023 at 3:38 pm
Here is what I came up with. If I had more time, I'd rewrite it to use closed-open intervals rather than open-closed intervals. (That is, I'd include the start date,...
October 10, 2023 at 6:14 pm
I prefer to use OFFSET/FETCH NEXT
to run batches of records in a loop. I've updated your query to reflect that.
October 5, 2023 at 5:14 pm
How are you ordering the data? I do not see what makes the second row come after first.
I didn't see anything specifying a filter based on order. The OP...
October 5, 2023 at 4:19 pm
When posting sample data to the web, you do not need to post EVERY SINGLE FIELD IN YOUR TABLE. More importantly, you could be in trouble for posting PII
October 3, 2023 at 2:36 pm
Any data type can be converted to binary, and it's impossible to tell from what you have given us what data type to convert back to. I tried VARCHAR, NVARCHAR,...
September 28, 2023 at 4:28 pm
drew.allen wrote:SELECT STRING_AGG(QUOTENAME(td.[name], ''''), ',')
FROM #tbl_db AS td;I prefer using CHAR instead of multiple single-quotes:
SELECT STRING_AGG(QUOTENAME(td.[name], CHAR(39)), ',')
FROM #tbl_db AS td;
I can never...
September 26, 2023 at 9:08 pm
SELECT STRING_AGG(CONCAT('''',td.name,''''),',')
FROM #tbl_db td
Instead of using CONCAT()
use QUOTENAME()
, in case your text contains single quotes. It will automatically create escaped forms of single quotes in...
September 26, 2023 at 2:10 pm
Viewing 15 posts - 31 through 45 (of 4,033 total)