首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

各位高人帮忙修改一存储过程!该怎么处理

2011-12-30 
各位高人帮忙修改一存储过程!!!alterproc[dbo].[Dis]asbegindeclare@insertstringvarchar(2000)declare@de

各位高人帮忙修改一存储过程!!!
alter   proc   [dbo].[Dis]  
as
begin

declare   @insertstring   varchar(2000)
declare   @deletestring   varchar(2000)
declare   @city   varchar   (50)

declare   cursor1   cursor   for   select   [Name]   from   table1
open   cursor1
fetch   cursor1   into   @city
while   (@@fetch_status   =   0)
begin

set   @insertstring   =  
'select   *   into   '   +   @city   +  
'   from     table2     where   [col1]   like ' ' '   +   @city+   '% ' ' '

set   @deletestring   =  
'delete   from   table2   where   [col1]   like   ' ' '+   @city+   '% ' ' '


begin   tran

exec(@insertstring)
if   @@ERROR <> 0
rollback   tran

exec(@deletestring)
if   @@ERROR <> 0
rollback   tran
commit   tran
fetch   cursor1   into   @city
end


close   cursor1
deallocate   cursor1

end

提示有错:第   33   行
COMMIT   TRANSACTION   请求没有对应的   BEGIN   TRANSACTION
请各位高手给于解决一下!!!

[解决办法]

alter proc [dbo].[Dis]
as
begin

declare @insertstring varchar(2000)
declare @deletestring varchar(2000)
declare @city varchar (50)

declare cursor1 cursor for select [Name] from table1
open cursor1
fetch cursor1 into @city
while (@@fetch_status = 0)
begin

set @insertstring =
'select * into ' + @city +
' from table2 where [col1] like ' ' ' + @city+ '% ' ' '

set @deletestring =
'delete from table2 where [col1] like ' ' '+ @city+ '% ' ' '


begin tran

exec(@insertstring)
if @@ERROR <> 0
begin
rollback tran
goto closeCur
end
exec(@deletestring)
if @@ERROR <> 0
begin
rollback tran
goto closeCur
end
commit tran

fetch cursor1 into @city
end

closeCur:
close cursor1
deallocate cursor1

end


-----------
try

热点排行