I’m looking for the Sum of time value differences between rows where Value was initially 1 and is now 0, grouped by Name. Example data for a single Name, but there are many different Names in the real data. This data should return 11 minutes for Row 9–>7 transition and 5 minutes for Row 4–…
Tag: sql-server
Split SQL Server Column value
I have a SQL Server table which name is AbundanceImpact. So I want the all integer values only with SUM. Answer Try this below logic- DEMO HERE
Rotate Database Table
Imagine I have a database table that has the following format: ╔══════════════════════╗ ║ Name Quarter Sales ║ ╠══════════════════════╣ ║ Joe Q1 700 ║ ║ Joe Q2 650 ║ ║ Joe Q3 …
Reading 0.5 value in ROW_NUMBER() and PARTITION BY | SQL Server 2012
I have this question before Looping between 2 case parameters (Date Range and Row Count) | SQL Server 2012 , now I’m thinking about a scenario, what if the value has a 0.5? or .5? Will this work using …
LAG function with two different partitions
I have a table with multiple calendars inside it and I need to get the previous business day for each row in the table. I’ve been trying to use the LAG function to achieve this but I’m unable to get the correct return for every item. I’ve ended up splitting it into two queries. When the day …
Can I use string_split with enforcing combination of labels?
So I have the following table: Id Name Label ————————————— 1 FirstTicket bike|motorbike 2 SecondTicket bike 3 ThirdTicket e-bike|…
Display date values as column
Below is my code to display date values as column name. But it won’t get the new data of the next month unless encoded in Pivot values. How should I do it dynamically? Below is the sample output. Answer You could use “real” dynamic SQL: First get your list of months and store it into a nvarc…
Rolling Sum when date is continuous
I’m trying to find how many days people have continuously worked in SQL. I’m thinking a rolling sum might be the solution but don’t know how to work it out. My sample data is | Employee | …
Bring a row into a column
I have the following table as my input: Date | Agent Name | Agent Department | Call ID | Transfer? | TransferToAgent_Dept ————————————————————————…
Select Distinct and sequence at the same time
How can I able to use Distinct on select statement along with a sequence on SQL Server I try this sub-query but no luck I get error of NEXT VALUE FOR function is not allowed in check constraints, …