将多个结果存储在可变... [英] Store multiple results in varaible...

查看:52
本文介绍了将多个结果存储在可变...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

declare @dist_No int
set @dist_no= select dist_No from megamart where sponsor_ID_No=11111
print @dist_no





以防我的查询返回一个结果(即@ dist_no = 1)它工作正常,我可以使用@dist_no



使用查询的结果,但是如果我的查询撤回两个结果怎么办

1

2

然后我怎么能存储它们

我怎么能用它们

例如我想用一些查询中有1个,另一个查询中有2个



in case my query is returning one result(i.e. @dist_no=1) it works fine and i can use query's result by using @dist_no

but what if my query is returing two results
1
2
then how can i store them
and how can i use them
for instance i want to use 1 in some queries and 2 in another queries

推荐答案

你可以使用 TABLE VARIABLES ,见这里:

http://odetocode.com/articles/365.aspx [ ^ ]

http://stackoverflow.com/questions/3838240/select-into-a-table-variable-in-t-sql [ ^ ]
You can use TABLE VARIABLES, see here :
http://odetocode.com/articles/365.aspx[^]
http://stackoverflow.com/questions/3838240/select-into-a-table-variable-in-t-sql[^]


据我所知我认为不可能。替代方法是使用表变量并将值存储在其中。您已经提到要使用它们,但不确定是否要在SQL中使用它们,只有这样才能使用此解决方案。
As far I know I don't think its possible. Alternative is use a table variable and store the values in it. You have mentioned you want to use them but not sure if you want to use them in SQL only if so then this solution should work.


这篇关于将多个结果存储在可变...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆