如何SQL用字符串给变量赋值
像下面这个语句,如果hb168_message30是一个变量的话,那么个SQL字符串语句(@STR)应该怎么写呢?
select @v_currentid = max(id) from hb168_message30 where id <= @v_currentid;
@str=?
------解决方案----------------------如何将exec执行结果放入变量中?
declare @num int,
@sqls nvarchar(4000)
set @sqls= 'select @a=count(*) from tableName '
exec sp_executesql @sqls,N '@a int output ',@num output
select @num