I need to find overlapping dates for a table. So the basic structure is ID, PFX, Start date, and end date. So where the PFX for a given ID is overlapping with another PFX for each ID. I tried this and had no luck. https://www.sqlservercentral.com/forums/topic/how-to-extract-overlapping-date-ranges-from-a-tabl…
Tag: sql-server
How to split lines in SQL table according to rules?
so I have SQL table with many lines. It looks like this (just a couple lines from the top): I need to disperse revenue according to project duration equally every 2 months starting first month. So desired result would look like this: What’s the baest way to achieve this? Answer You can use recursive cte…
Replace Null with ‘-‘ string in Dynamic Pivot query
I have the following code where I’m trying to dynamically Pivot the table. Everything seems to be working the way I want except I want to replace the null with ‘-‘. Any ideas? Answer You need to put the coalesce into the dynamic column list – something like this: The isnull(@Columns1&#…
How to sum multiple rows on trigger update?
I wrote a trigger on update on table [CART] to count and insert value to other table [HEADERS] to column [SUM]. It works but only for 1 row where [CART].[NUMBER] = [HEADERS].[NUMBER]. Column [NUMBER] …
SQL output parameter of varbinary to use as image on ASPX web form
I am trying to retrieve the logo stored into my table and display the image from the database to my aspx web page. I have output parameters in a SQL stored procedure which output the name and a …
Switch case with storing results into same table in SQL
I want to store the results into table with same name as per the condition. How to achieve the same ? Following is the code: While executing it throws error that #a already exists. IF @Input =’1′ …
Insist on number of rows on left side of join
I have an issue where I want to join two tables where there is 1 record on the left and many on the right side but only need information from the right that exists in all of those records – in other words, insist on only getting 1:1 not 1:n in my results. Example, if I run this statement below,
How to Merge Identical Rows with different column?
I have a table like this: ——————————————– | Job | Class | Employee | PayType | Hours | | 212 A John 1 20 | | 212 A John 2 …
How to distinct with condition
I am working on T-SQL. I got a table like this. x y z t 1 avc 45353 11.02.2019 2 avc 24324 29.05.2019 3 frg 54647 30.06.2019 3 dsc 35678 29.05.2019 4 dec 21445 13.04.2019 4 …
Problem in getting this output using Join in SQL Server
I want to show a output like this, +————+————–+———————+—————+———–+————–+———–+ | segment_id | segment_name …