Tag Info

New answers tagged


I was able to write a Query to resolve this issue. It uses multiple joins and a while loop to merge records. This code is compatible with SQL Server 2008 R2. CREATE TABLE #mergeTest ( [id] int NOT NULL, [data] date, [from] date NOT NULL, [to] date NOT NULL ); INSERT INTO #mergeTest ([id],[data],[from],[to]) VALUES --testing null data ...


I wrote a query that seems to work. It uses Common Table Expressions, MERGE statements and Analytic functions. However it is only compatible with SQL server 2012+. You can find the gist here: MergeRecordsByValidityDate.sql /* NOTE: Only works w/ SQL Server 2012+ Merging identical records with different validity dates. */ USE [master] IF ...

Top 50 recent answers are included