Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

how to add blank rows between groups of duplicate rows?

$
0
0

here is my setup

create table #tmpA(rowID int identity(1,1), fName varchar(10), lName varchar(10))

insert into #tmpA
select 'a', 'b' union all
select 'a', 'b' union all
select 'c', 'd' union all
select 'c', 'd' union all
select 'e', 'f' union all
select 'e', 'f' union all
select 'g', 'h' union all
select 'g', 'h'

select distinct fName, lName
into #tmpB
From #tmpA

select t1.* from #tmpA t1 Join #tmpB t2 on t1.fName = t2.fName and t1.lName = t2.lName

--output

rowID  fName  lName
1             a         b
2             a         b
3             c         d
4             c         d
5             e         f
6             e         f
7             g         h
8             g         h

I want to add blank rows between rows 2 & 3 and between rows 4 & 5 and between rows 6 & 7 in the join query above.  Is there Tsql that can accomplish something like this to make the join query result look like the following output?


rowID  fName  lName
1            a          b
2            a          b

3            c          d
4            c          d

5            e          f
6            e          f

7            g          h
8            g          h

or if this is not possible I could go with an output like this:

rowID  fName  lName
1             a         b
2             a         b
3
4             c         d
5             c         d
6
7             e         f
8             e         f
9
10           g         h
11           g         h


Rich P


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>