-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNovocursor.sql
41 lines (33 loc) · 1.4 KB
/
Novocursor.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
--select * into [Person].[EmailAddress_bkp] select * from [Person].[EmailAddress]
--select a.BusinessEntityID, * from [Person].[EmailAddress] a where a.EmailAddress is null
--update [Person].[EmailAddress] set EmailAddress = null where BusinessEntityID between 189 and 210
--update [Person].[EmailAddress] set EmailAddress = '[email protected]' where BusinessEntityID = 201
declare @email varchar(max), @id int
declare cursorAtualizaEmail cursor
for select BusinessEntityID, EmailAddress from person.[EmailAddress_bkp] a where BusinessEntityID between 189 and 210
open cursorAtualizaEmail
fetch next from cursorAtualizaEmail
into @id, @email
while @@FETCH_STATUS = 0
begin
if (select EmailAddress from [Person].[EmailAddress] where BusinessEntityID = @id) is null
begin
update [Person].[EmailAddress]
set EmailAddress = @email
where BusinessEntityID = @id
select EmailAddress from [Person].[EmailAddress] where BusinessEntityID = @id
fetch next from cursorAtualizaEmail
into @id, @email
end
else
begin
fetch next from cursorAtualizaEmail
into @id, @email
end
end
close cursorAtualizaEmail
deallocate cursorAtualizaEmail
--select * from [Person].[EmailAddress] where BusinessEntityID between 189 and 210
update [Person].[EmailAddress]
set EmailAddress = (select EmailAddress from [Person].[EmailAddress_bkp] where BusinessEntityID = 201)
where BusinessEntityID = 201