【发布时间】:2016-01-06 12:31:34
【问题描述】:
在 ADO.Net 中运行的 SQL 命令字符串。问题它可能在子查询中返回超过 1 行。
string str = "
select
(select (quantity) from Orderinfo where iron=1 and rno=o.rno) as iron
,(select (quantity) from Orderinfo where wash=1 and rno=o.rno) as wash
,(select (quantity) from Orderinfo where dryclean=1 and rno=o.rno) as dryclean
,o.rno
,o.id
,o.name
,(select sum(convert(int,d.quantity)) from orderinfo as d where d.rno=o.rno) as quantity
,o.status
from orderinfo as o
where o.status='Order in Process'
group by o.rno,o.id ,o.status ,o.name";
【问题讨论】:
-
使用 select top 1....... 代替。
-
请谨慎对待您的 SQL 查询,它们应该与您的应用程序代码一样具有可读性、可维护性和清晰性。
标签: sql