我正在使用以下查询 SELECT @local_variable=Adtid from table where Adtid可以存储多个值。 因为我不知道在@ local_variable = Adtid中使用什么而不是'='。 任何人都可以建议我应该使用什么而不是'=',以便我的本地变量可以拥有Adtid的所有值
I am using below query SELECT @local_variable=Adtid from table where Adtid can have multiple values stored into it. As I don't know what to use instead of '=' in @local_variable=Adtid. Can anyone suggest please what I should use instead of '=' so that my local varaible can have all values of Adtid
最满意答案
该变量实际上不能包含多个值。 您可以改为声明一个表变量,然后可以执行类似的操作
declare @tableVariable table ( Adtid int ); insert into @tableVariable select Adtid from table where Adtid ...这会将相关行放在表变量中。 现在你可以使用表变量来例如。 创建一个游标(在数据中逐行进行 - 如果只需要经历一次,也可以在原始选择上执行此操作)或在join子句中使用它。
The variable can't actually hold multiple values. You can declare a table variable instead, where you can then do something like
declare @tableVariable table ( Adtid int ); insert into @tableVariable select Adtid from table where Adtid ...This puts the relevant rows inside your table variable. Now you can use the table variable to eg. create a cursor (to go row by row in the data - you can also do that on the original select if you only need to go through once) or use it in a join clause.
更多推荐
发布评论