儲存過程例子

2021-05-26 07:25:10 字數 4176 閱讀 7844

alter proc [futurema].[updageorderdatasdistinguishresult] 

asdeclare @connectionstring nvarchar(256)

declare @server nvarchar(256)

declare @uid nvarchar(256)

declare @pwd nvarchar(256)

declare @database nvarchar(256)

declare @svrlink nvarchar(50)

declare @sql nvarchar(1000)

declare @orderid uniqueidentifier

declare @ordercount int,@i int,@datacount int,@dc int

set @i=0

--定義存放受番號的臨時表

declare @temp_perorders table(orid uniqueidentifier,datacount int, storedb nvarchar(max) )

--找到全部需要處理的受番號

insert into @temp_perorders(orid ,datacount,  storedb )

select orderdatas.orderid,

orderdatas.datacount,

storeservers.accessinformation

from futuremanagement_manage.futurema.orderdatas with(nolock)

inner join  futuremanagement_masters.futurema.storeservers with(nolock)   

on     orderdatas.storeservers.value('(/ss/s[@type=2])[1]', 'int') = storeservers.storeserverid

where matterid =0  and

finishdatetime is null and

orderdatas.orderproperty.value('(/op/dc)[1]', 'int') <> orderdatas.datacount

select @ordercount = count(*) from @temp_perorders  

if @ordercount=0

return

while @i<@ordercount 

begin

set rowcount @i

select 

@orderid = orid,

@datacount = datacount,

@connectionstring =storedb 

from @temp_perorders

--print @orderid 

--print @connectionstring

declare    @temp_connectinfo table

info nvarchar(50)

if (@connectionstring is not null) and len (@connectionstring)> 0 

begin

insert into @temp_connectinfo

select   substring(connectinfo,b.number,charindex(';',connectinfo+';',b.number)-b.number)  as info  

from (select  @connectionstring connectinfo) op

join master..spt_values as b

on b.type='p' and b.number >0 and substring(';'+connectinfo,b.number,1)=';'

endselect @server  = substring(info, charindex('=',info)+1,len(info) - charindex('=',info)  ) from @temp_connectinfo where info like 'server%'

select @uid  = substring(info, charindex('=',info)+1,len(info) - charindex('=',info)  ) from @temp_connectinfo where info like 'uid%'

select @pwd  = substring(info, charindex('=',info)+1,len(info) - charindex('=',info)  ) from @temp_connectinfo where info like 'pwd%'

select @database  = substring(info, charindex('=',info)+1,len(info) - charindex('=',info)  ) from @temp_connectinfo where info like 'database%'

begin try

set  @svrlink = newid()

--建立鏈結伺服器

exec   sp_addlinkedserver     @svrlink, ' ', 'sqloledb ', @server

exec   sp_addlinkedsrvlogin   @svrlink, 'false',null, @uid, @pwd 

exec sp_serveroption @svrlink, 'rpc', 'on' 

exec sp_serveroption @svrlink, 'rpc out', 'on'

if (@@rowcount = 1)

begin

declare @description nvarchar(1000)  ,

@distinguishcount int   

set @sql = '  

['+@svrlink+'].[futuremanagement_procedure].[futurema].[getdistinguishmattertype] 

@orderid= @orderid,

@description = @description output,

@distinguishcount = @distinguishcount  output

exec sp_executesql  @sql,

n'@orderid uniqueidentifier ,@description nvarchar(1000) output,@distinguishcount int output',

@orderid  ,

@description  output,

@distinguishcount   output

--print @orderid

--print  @description

--print @distinguishcount

update futuremanagement_manage.futurema.orderdatas

set orderproperty.modify('replace value of(/op/dc[1]/text())[1] with sql:variable("@distinguishcount")')  

where orderid  = @orderid

update futuremanagement_manage.futurema.orderdatas

set orderproperty.modify('replace value of(/op/dd[1]/text())[1] with sql:variable("@description")')

where orderid  = @orderid

end--刪除鏈結伺服器  

exec   sp_dropserver   @svrlink,'droplogins'

end try

begin catch

----刪除鏈結伺服器

exec   sp_dropserver   @svrlink,'droplogins'

end catch

set @i += 1

end

儲存過程例子

create table testtb id varchar2 30 name varchar2 30 insert into testtb values 1 21 insert into testtb values 2 22 insert into testtb values 3 23 inser...

mysql 儲存過程 例子 MySQL儲存過程例子

索引 index create index idx sname on student sname 4 alter table teacher add index idx tname tname drop index idx sname on student 檢視 view create view v...

儲存過程的例子

帶引數儲存過程讀資料 public static void procinputreader sdr.close conn.close 帶 引數 輸出 儲存過程讀資料 output public static void procinputreader1 帶 引數 輸出 儲存過程讀資料 return 用...