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 …
Tag: sql-server
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
Sum the results of a DateDiff [closed]
I have a table with 3 columns: SessionRole (varchar(100)), Start Date (datetime2(7)) and End Date (datetime2(7)). I need to calculate a value that is the sum of End Time – Start Time for all sessions …
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’…
Inserting an ID that increments (but is not an AUTOINCREMENT)
I have a table that I am trying to insert multiple records into using a select statement. The ID field is an INT and not autoincremented but I do need to increment in in the INSERT. The table belongs to a third party product we use for our ERP so I cannot change the property of the ID. The insert
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….
SQL get value from XML in tag, by tag value
I have the following XML: TEST1 D028 …