--开启
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
--关闭Ad Hoc Distributed Queries组件,在sql查询编辑器中执行如下语句:
exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure
alter PROCEDURE lf_GroupName
AS
declare @groupId int,@groupName varchar(20)
declare mycursor cursor for
select G.groupId as groupId,GS.groupName as groupName from OPENDATASOURCE(
'SQLOLEDB',
'Data Source=192.168.1.30;User ID=sa;Password=sa123456!'
).xxxx.dbo.[Group] G
left join [group] GS on G.groupId=GS.groupId
where GS.groupid = 49
open mycursor
fetch next from mycursor into @groupId,@groupName
while(@@fetch_status = 0)
begin
update OPENDATASOURCE(
'SQLOLEDB',
'Data Source=192.168.1.30;User ID=sa;Password=sa123456!'
).xxxx.dbo.[Group] set groupName= @groupName where groupId=@groupId
fetch next from mycursor into @groupId,@groupName
end
close mycursor
deallocate mycursor
GO