存储过程中,语句中表名是上一个select搜出来的,老出错!!!
declare @tblName varchar(50)
select @tblName=dx_dbtable from #ls_dxtable where id=@id
set @tblName= 'tbo_ '+@tblName--拼接要查找的表名
select @jtdxSumCount=Count(*) from @tblName where isEnd=0 and isdelete=0(这个语句里老是提示说@tblName为定义,为什么啊?)
------解决方案--------------------declare @sql nvarchar(1000),@jtdxSumCount int
set @sql = N 'select @jtdxSumCount=Count(*) from ' + @tblName + N ' where isEnd=0 and isdelete=0 '
exec sp_executesql @sql, N '@jtdxSumCount int output ', @jtdxSumCount output
------解决方案--------------------表名为变量的话,要使用动态SQL语句 正如上边的语句