I have a table that has the below data. I wrote a query that will calculate the sum of cumulative rows and got the below output . Now I want to to filter the data and take only where the POOL <=300, if the POOL field does not have the value 300 then I should take the first value after
Tag: tsql
Group by the records and that particular group if condition matched then set final result like below
I want to group by the records and that particular group if the condition matched then set final result like below For each group, I want to check the following condition Answer You can use conditional logic: Here is a db<>fiddle.
Get the count of records from another table
I have a view that looks like this: which is defined using this SQL statement: Now I want to count the records for another table (TABLE 2) based on the C_CODE, P_CODE and PH_CODE and display it as a column TOTAL in my view. How can I do this? Answer one way is to use subquery:
Return records that only have a certain status from a select query that includes multiple joins
I have a query: That returns records such as these: I want to be able to only return records that only have ‘I’ values under Inv_Disp where the Order_Num may or may not be the same. But where if an Order_Num Inv_Disp contains an ‘I’ AND some other value such as ‘CH’ or ‘P’ that it would not return the
SUM with Multiple Conditions
I’m writing a query on SQL Server and have hit a wall on cumulative sum with multiple conditions. I need to sum all the purchases in a day made by a user, I can do it separately, sum purchases by day(Daily_Total), or sum purchases by user(User_Total), but I run into a wall when I need both conditions met(User_Daily_Total). I tried
Compare 3 SQL Server tables and once matched based on some attribute put the result on one table when not matched put the result in another
I have the simple requirement, there are the 3 SQL Server tables like this: Table 1; columns Table 2; columns Table 3; columns I wish to join (inner joins) based on Name, DOB, Gender & PostCode across all the tables, if the record matches I would like to put the result in one table and the remaining records I wish
Group data in intervals
I need to group data in intervals of 15 (or X) minutes in sql. For example, i have the next scenario. The result that i expect to obtain is I tried using Lag function but i dont get what i want, because it add interval to each row and continues grouping. Thanks in advance and apologies for my bad english.
T-SQL Trigger – Audit Column Change
Given a simple table, with an ID what is the correct way to audit a column being changed. I am asking after looking after various answers which seem not to be working. Here is what I have: Create …
Trying to update Date Format from (DD-MM-YYYY) to (MM-YYYY) SQL
I’m trying to update my date column which is (eg. 2012-04-20) format in into mm-yyyy. I searched for solutions that you can do by converting to varchar however it gave me an error Msg 241, Level 16, State 1, Line 4 Conversion failed when converting date and/or time from character string. This is the code I’m executing Any idea how
SQL Select One Record over another based on column value
What I am trying to do is select rows based off of a ‘priority’. Say I have this: I want to choose one row each for the control ids (the whole row), which would be the third row, because there is no priority, and the 2nd row becuase it has priority. So if I have two control IDs that are