وعليكم السلام
استعمل هذا الكود داخل قاعدة البيانات الرئيسية Dynamics
كود:
USE DYNAMICS
set nocount on
declare @aaUserid char(15)
declare cCEIP cursor for
select A.USERID
from SY01400 A left join SY01402 B on A.USERID = B.USERID and B.syDefaultType = 48
where B.USERID is null or B.SYUSERDFSTR not like '1:%'
open cCEIP
while 1 = 1
begin
fetch next from cCEIP into @aaUserid
if @aa@aaFETCH_STATUS <> 0 begin
close cCEIP
deallocate cCEIP
break
end
if exists (select syDefaultType from DYNAMICS.dbo.SY01402 where USERID = @aaUserid and syDefaultType = 48)
begin
print 'adjusting ' + @aaUserid
update DYNAMICS.dbo.SY01402
set SYUSERDFSTR = '1:'
where USERID = @aaUserid and syDefaultType = 48
end
else begin
print 'adding ' + @aaUserid
insert DYNAMICS.dbo.SY01402 ( USERID, syDefaultType, SYUSERDFSTR )
values ( @aaUserid, 48 , '1:' )
end
end /* while */
set nocount off