当前位置: 代码迷 >> Sql Server >> 帮忙看下此存储过程解决办法
  详细解决方案

帮忙看下此存储过程解决办法

热度:47   发布时间:2016-04-27 15:04:45.0
帮忙看下此存储过程
create Proc P_Check1 
  @DelTable varchar(50)  
  as
  declare @count int,
  @count1 int,  
  @DelID varchar(50),  
  @DelIDValue varchar(50),  
  @CheckTable varchar(50),  
  @CheckField varchar(50),  
  @Mess varchar(50),  
  @sql nvarchar(4000), 
  @sql1 varchar(4000) output
   
  begin --判断表是否存在  
  select @count=COUNT(1) from MasterCheck where [email protected]
  if @count>0
  begin --检测
  select @DelID=DelID,@DelIDValue=DelIDValue,@CheckTable=CheckTable,@CheckField=CheckField,@Mess=Mess
  from RecordCheck where DelTable = @DelTable
  print(@CheckField)
  set @sql='select @count1=COUNT(1) from [email protected]+' where [email protected][email protected]+''''
  print(@sql)
  exec sp_executesql @sql,[email protected] int',@count1 
  print(@count1)
  if @count1>0
  print('有内容')
  else
  print('直接删除')
  end
  else
  print('此表不存在')
  end
  go


  print(@sql)和print(@count1)都没法输出,我也不知道count1是否得到了正确结果,但是最终输输出的是'直接删除',这个结果是不对的,应该输出'有内容',请帮我看一下错误出在哪里!谢谢!



------解决方案--------------------
SQL code
create Proc P_Check1    @DelTable varchar(50)     as  declare @count int,  @count1 int,     @DelID varchar(50),     @DelIDValue varchar(50),     @CheckTable varchar(50),     @CheckField varchar(50),     @Mess varchar(50),     @sql nvarchar(4000),    @sql1 varchar(4000) output      begin --判断表是否存在     select @count=COUNT(1) from MasterCheck where [email protected]  if @count>0  begin --检测  select @DelID=DelID,@DelIDValue=DelIDValue,@CheckTable=CheckTable,@CheckField=CheckField,@Mess=Mess  from RecordCheck where DelTable = @DelTable  print(@CheckField)  set @sql='select @count1=COUNT(1) from [email protected]+' where [email protected][email protected]+''''  print(@sql)  exec sp_executesql @sql,[email protected] int output',@count1  output  print(@count1)  if @count1>0  print('有内容')  else  print('直接删除')  end  else  print('此表不存在')  end  go
------解决方案--------------------
SQL code
create Proc P_Check1    @DelTable varchar(50)     as  declare @count int,  @count1 int,     @DelID varchar(50),     @DelIDValue varchar(50),     @CheckTable varchar(50),     @CheckField varchar(50),     @Mess varchar(50),     @sql nvarchar(4000),    @sql1 varchar(4000) output      begin --判断表是否存在     select @count=COUNT(1) from MasterCheck where [email protected]  if @count>0  begin --检测  select @DelID=DelID,@DelIDValue=DelIDValue,@CheckTable=CheckTable,@CheckField=CheckField,@Mess=Mess  from RecordCheck where DelTable = @DelTable  print(@CheckField)  set @sql='select @count1=COUNT(1) from [email protected]+' where [email protected][email protected]+''''  print(@sql)  exec sp_executesql @sql,[email protected] int output',@count1  output  print(@count1)  if @count1>0  print('有内容')  else  print('直接删除')  end  else  print('此表不存在')  end  go
  相关解决方案