Viewing 15 posts - 76 through 90 (of 4,075 total)
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
For a running total - you can use: thisBalance = SUM(thisAmt) OVER(PARTITION BY Batch_Id ORDER BY Id)
If you want to break out the totals even further, add those to...
September 17, 2023 at 7:05 pm
I've updated the code to a) use a temp table instead of a permanent table. Here is the setup code:
DROP TABLE IF EXISTS #charges;
CREATE TABLE #charges (
...
September 14, 2023 at 8:53 pm
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
Viewing 15 posts - 76 through 90 (of 4,075 total)