Skip to content

Tag: sql-server

Calculating a plug/balance in SQL

My current table has a few accounts which always have minimal values (example, X & Y for actual and AA, BB, CC & DD for plan) in current table. Accounts with minimal values can extend beyond these accounts. I need to categorize such accounts into proxy account called “balance” which would …

Calculate time in List without using a loop

Is there a way to calculate the data on my List without using loop? My concern right now is it takes longer to process the 5000 ids of employee with different LogIn and LogOut using for loop in a week. What i’ve done is the data is uploaded from csv to the database. Once all the data is uploaded i

Applying Logic to Sets of Rows

I want to add logic that calculates price per claim. Below, there are two claims, one for patient 5, and another for patient 6. Original idea is to create a unique list of patient numbers in a …

SQL rolling average that restarts on gaps

I have values that come in every 1 hour and I need to do an 8-hr rolling average. The catch is that this rolling average has to “restart” when there is a gap. Please see the table below (my desired output), as you can see, the value for 14:45 is missing, so the average for 15:45 is that row’…

Categorize the total amounts

I have a query that gave me a list of store names and its respective amounts. However I would like to sum and categorize the amounts like this: Store Name | $0-$50 | $50 – $100 | $100 – $500 | $500+ Based on the following screenshot: Here is my condition: Here is my basic query for the above snaps…

List count for last 12 months broken down by month

I have a query that can get a total active count of products until a specified date @POINT Output for @POINT “01/01/2021” is From a table like How would I remake this query so that I can have a list of points (last 12 months) like in one query? I don’t want to create a separate table of date…

SQL – sum column for every date

This seemed like a very easy thing to do but I got stuck. I have a query like this: select op.date, count(p.numberofoutstanding) from people p left join outstandingpunches op on p.fullname = op….