转载自http://blog.csdn.net/xb12369/article/details/8202703

假设存储过程:proc_test

create proc proc_test

@ProdID varchar(10)

as

begin

declare @sql varchar(max)

@sql = " select * from test  where 1=1"

if @ProdID <> ''

set @sql += ' and prodid=''' + @ProdID + ''''

set @sql += ' order by Id desc'

exec @sql

end

 

然后执行存储过程:会弹出 名称 不是有效的标识符 sql

为什么?

因为exec的时候,掉了()

 

正解是:exec  (@sql)

相关文章:

  • 2022-01-05
  • 2021-12-06
  • 2022-03-01
  • 2022-12-23
  • 2022-12-23
  • 2022-02-25
  • 2022-12-23
  • 2021-12-18
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案