日期:2014-05-18  浏览次数:20577 次

动态存储过程sql相关问题
CREATE       PROCEDURE     SP_PDeal
    AS
declare   @sql1   varchar(500)
declare   @sql2   varchar(500)
declare   @count1   int
set   @sql1= 'select   ' '@count1 ' '=count(*)   from   a '
set   nocount   on
begin
EXEC(@sql1)
if   @count1> 0
begin
set   @sql2= 'update   a   set   b= ' 'c ' '   where   UniqueID=2 '
exec(@sql2)
end
end
GO


------解决方案--------------------
CREATE PROCEDURE SP_PDeal
AS
declare @sql1 nvarchar(500)
declare @sql2 nvarchar(500)
declare @count1 int
set @sql1= 'select @count1=count(*) from a '
set nocount on
begin
EXEC sp_executesql @sql1, N '@count1 int output ', @count1 output
if @count1> 0
begin
set @sql2= 'update a set b= ' 'c ' ' where UniqueID=2 '
exec(@sql2)
end
end
GO