如何使用T-SQL中的特定值替换缺失的行

时间:2017-06-08 10:23:32

标签: sql-server tsql

我需要在查询中生成报告:

select cIDNum,cvisitNo, cgender
from table detail

访问的某些记录未输入数据库,因此丢失。现在我想在查询中修改缺少的访问行,以便我按如下方式进行:

l256T, 0,F
l256T, 1,F
l256T, 2,F
l256T, 3,F
l256T, 4,F
l256T, 5,F
l256T, 6,F    

1 个答案:

答案 0 :(得分:0)

你可以尝试这样的事情:

;With cte1 as 
( select * from (values (1),(1),(1),(1),(1),(1),(1),(1),(1),(1)) a(n) )
,Cte2 as ( select c1.* from cte1 c1, cte1 c2, cte1 c3)
,numbers as ( select RowN = row_number() over (order by (select null))-1  from cte2 c1, cte2 c2)
Select td.cidNum, RowN as cVisitNo, td.cgender from Numbers n
    Left join tableDetail td
    on n.RowN = td.VisitNo