我有这样的查询:
DECLARE @razem VARCHAR(MAX);
SELECT Ordering.orderID ,
Document.number,
(User_info.name +' '+ User_info.surname),
Ordering.dateStart,
Ordering.dateEnd ,
(
select COALESCE(' ',@razem)+sell_type.name as r
from Ordering_sell_type, Sell_type
where orderID = Ordering.orderID and
Ordering_sell_type.sell_typeID = sell_type.sell_typeID
) podz
FROM Ordering, User_info, Product_Document, Document, Document_type
WHERE Ordering.orderID = Product_document.orderID
AND Document.documentID = Document_type.documentID
AND Document.documentID = Product_document.documentID
AND Ordering.userID = User_info.userID
AND Ordering.isClosed = 1 AND Document_type.typeID = 1
GROUP BY Document.isitfiscal, Document.refDocID,
Document.number, Ordering.orderID, User_info.name,
User_info.surname, Ordering.dateStart,
Ordering.dateEnd , Ordering.isCLosed
ORDER BY Ordering.dateEnd
在那个 COALESCE 函数中,我想获取所选订单的所有支付类型 - 例如,orderID 123 有 payTypes = Card、Cash,orderID 有 payTypes = Cash。
问题是我想把它放在一个简单的行中作为主查询的最后一行,比如:orderID、Document.number、UserInfo.name+surname、dateStart、dateEnd、->card、cash<- 但是在尝试像上面这样的查询之后我得到了错误:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
因为它返回不止一行。是否有可能在子查询中获取支付类型并作为一个字符串返回?