sql语句,OrzDECLARE @qdatetime,@a datetime DECLARE @pdatetime,@ldatetime SET @q2011-06-21SET @a
sql语句,Orz
DECLARE @q datetime,@a datetime DECLARE @p datetime,@l datetime SET @q='2011-06-21'SET @a='2012-06-21' SET @p='2011-06-23'SET @l='2012-06-23' 我有这样的语句
能不能想办法用#params#代替后面的set部分
#params#是 and @q='2011-06-21' and @a='2012-06-21'
and @p='2011-06-23' and @l='2012-06-23'的意思
其实就是要实现replace(#params#,'and','set')
但是是写的语句不是查询信息。
不知道我描述清楚了没。求大家给我想办法,思路也行
[最优解释] declare @sql string(800) @sql =' Set '+@q+'=''2011-06-21'' ,Set '+@q+'=''2011-06-21'' , Set'+@a+'=''2012-06-21'' ,Set '+@p+'=''2011-06-23'' ,Set '+@l+'=''2012-06-23'' exec(@sql) [其他解释] 用动态语句
然后exec()
[其他解释] 没看啥明白#params#是什么
[其他解释] 引用: 用动态语句 然后exec() 能就我上面那个例子具体写下怎么个转换法吗?谢谢拉
[其他解释] 引用: 没看啥明白#params#是什么 #params#就是一个字符串是and @q='2011-06-21' and @a='2012-06-21'
and @p='2011-06-23' and @l='2012-06-23'这样的一个字符串
[其他解释] declare @sql string(800) @sql =' and +'+@q+ ' ='2011-06-21' and '+@a+'='2012-06-21' and '+@p+'='2011-06-23' and '+@l+'='2012-06-23' [其他解释] 引用: SQL code? 1234 declare @sql string(800) @sql =' and +'+@q+ ' ='2011-06-21' and '+@a+'='2012-06-21' and '+@p+'='2011-06-23' and '+@l+'='2012-06-23' 我想用#params# 来代替 SET @q='2011-06-21'SET @a='2012-06-21'SET @p='2011-06-23'SET @l='2012-06-23'
怎么写呢?
[其他解释] 引用: SQL code? 1234 declare @sql string(800) @sql =' Set '+@q+'=''2011-06-21'' ,Set '+@q+'=''2011-06-21'' , Set'+@a+'=''2012-06-21'' ,Set '+@p+'=''2011-06-23'' ,Set '+@l+'=''2012-06-23'' exec(…… 谢谢。
可能我没说清楚,我想用#Params#来代替那段set语句。相当于我要实现这样的效果
DECLARE @q datetime,@a datetime DECLARE @p datetime,@l datetime
replace(#params#,and,set)
[其他解释] 也就是不要set那部分 用#params#来代替