Skip to content

Tag: sql-server

Need to identify overlapping dates

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…

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&#…

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,