SELECT @ local

编程入门 行业动态 更新时间:2024-10-28 20:24:41
SELECT @ local_variable =表中的值,其中值可以有多个值(SELECT @local_variable=values from table where values can have multiple values)

我正在使用以下查询 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.

更多推荐

本文发布于:2023-07-16 00:09:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1120990.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:SELECT   local

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!