游标
Declare @EntryTime Nvarchar(100) --入职时间
Declare @EhrNo Nvarchar(100) --Ehr编号
DECLARE CusPostCursor CURSOR FOR
select B.EntryTime,A.EhrNo from tableA A left join tableB B on A.EhrNo = B.EhrNo
--打开游标
OPEN CusPostCursor
--读取游标中的值 遍历每条数据 获取
fetch next from CusPostCursor into @EntryTime,@EhrNo
while @@fetch_status<>-1
begin
--业务
Update tableA set EntryTime = @EntryTime where EhrNo = @EhrNo
--读取下个游标的值
fetch next from CusPostCursor into @EntryTime,@EhrNo
end
--关闭游标
close CusPostCursor
--释放游标
deallocate CusPostCursor
查询重复数据
--单列查重
select * from test
where name in (select name from test group by name having count
(name) > 1)
--多列查重
SELECT a.* FROM test a,(
SELECT name,code
FROM test
GROUP BY name,code
HAVING COUNT(1)>1
) AS b
WHERE a.name=b.name AND a.code=b.code