从选择结果约束中设置

时间:2018-11-19 04:02:49

标签: sql-server

我可以在视图中设置多于1个结果的参数吗?

Declare @input varchar(1000)
SET @input = (select order from orderlist_view)

我收到的错误是:Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

2 个答案:

答案 0 :(得分:0)

您可以使用XML完成此操作:

Declare @input varchar(1000)


select @input = stuff((select distinct ',' + quotename(order)
            from orderlist_view
            for xml path(''), type).value('.', 'nvarchar(max)'),1,1,'')

这项工作可以吗?

答案 1 :(得分:0)

您可以改为声明一个表,并执行以下任务:

declare @table table(column_name varchar(1000))
insert @table
select order from orderlist_view

-打印声明的表变量

select * from @table.