欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

SQL语句中的一些参数如何用变量来代替?_MySQL

程序员文章站 2022-06-10 18:14:01
...
可以采用exec方法
declare @tempStr varchar(350)
select @tempStr='Update weekcount set [' convert(varchar,@week) ']=[' convert(varchar,@week) '] 1 where
userid=''' replace(@user,'''','''''') ''''
exec(@tempStr)
注意: 使exec不能返回一些变量的值,而且当前的变量值在exec的语句里无效.