日期:2014-05-18 浏览次数:20432 次
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 DelTable=@DelTable 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 '+@CheckTable+' where '+@CheckField+'='''+@DelIDValue+'''' print(@sql) exec sp_executesql @sql,N'@count1 int output',@count1 output print(@count1) if @count1>0 print('有内容') else print('直接删除') end else print('此表不存在') end go
------解决方案--------------------
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 DelTable=@DelTable 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 '+@CheckTable+' where '+@CheckField+'='''+@DelIDValue+'''' print(@sql) exec sp_executesql @sql,N'@count1 int output',@count1 output print(@count1) if @count1>0 print('有内容') else print('直接删除') end else print('此表不存在') end go