实现效果:
相关代码:
DECLARE @count int
set @count =
(select count(*) From dic_sex_code)
--偶数行
if @count % 2 = 0
begin
select DISTINCT d1.*,d2.* from
(select row_number() over(order by code) as num,* From dic_sex_code) as d1,
(select row_number() over(order by code) as num,* From dic_sex_code) as d2
where
d1.num % 2 = 1
and d2.num % 2 = 0
and d1.num + 1 = d2.num
end
--奇数行
ELSE
begin
select DISTINCT d1.*,d2.* from
(select row_number() over(order by code) as num,* From dic_sex_code) as d1,
(select row_number() over(order by code) as num,* From dic_sex_code) as d2
where
d1.num % 2 = 1
and d2.num % 2 = 0
and d1.num + 1 = d2.num
UNION all
select d3.*,'','','','','','' from
(select row_number() over(order by code) as num,* From dic_sex_code) as d3
where
num = @count
end