您好我有一个选择内部加入声明似乎没问题,但我收到了错误。这是我的查询
ALTER PROCEDURE [dbo].[POBalance] @PONumber nvarchar(50)
AS BEGIN
Select(
Select
A.Description,
C.qty as POqty,
B.QtyDelivered as PDQty,
case when A.partialflag ='false'
then '0'
else
A.qty end as Balance,
A.Unit,
A.Unitprice,
A.Partialflag
from tblPOdetails as A
Inner Join ( SELECT id, SUM(Qty) AS QtyDelivered
FROM dbo.tblPDdetails
WHERE (PONo = @PONumber)
GROUP BY id)as B On A.id = B.id
Inner Join tblpodetailshistory as C on A.id =C.id
where A.PONo = @PONumber)
END
我收到了这个错误。
当选择列表中只能指定一个表达式时 子查询不是用EXISTS引入的。
先谢谢你。
答案 0 :(得分:0)
您应该在外部选择语句
中包含列名和From关键字ALTER PROCEDURE [dbo].[POBalance] @PONumber nvarchar(50)
AS BEGIN
Select Description, POqty, PDQty, Balance, Unit, Unitprice, Partialflag from (
Select
A.Description,
C.qty as POqty,
B.QtyDelivered as PDQty,
case when A.partialflag ='false'
then '0'
else
A.qty end as Balance,
A.Unit,
A.Unitprice,
A.Partialflag
from tblPOdetails as A
Inner Join ( SELECT id, SUM(Qty) AS QtyDelivered
FROM dbo.tblPDdetails
WHERE (PONo = @PONumber)
GROUP BY id)as B On A.id = B.id
Inner Join tblpodetailshistory as C on A.id =C.id
where A.PONo = @PONumber)
END
实际上你不需要编写外部选择,它可以重写为
ALTER PROCEDURE [dbo].[POBalance] @PONumber nvarchar(50)
AS BEGIN
Select
A.Description,
C.qty as POqty,
B.QtyDelivered as PDQty,
case when A.partialflag ='false'
then '0'
else
A.qty end as Balance,
A.Unit,
A.Unitprice,
A.Partialflag
from tblPOdetails as A
Inner Join ( SELECT id, SUM(Qty) AS QtyDelivered
FROM dbo.tblPDdetails
WHERE (PONo = @PONumber)
GROUP BY id)as B On A.id = B.id
Inner Join tblpodetailshistory as C on A.id =C.id
where A.PONo = @PONumber
END
答案 1 :(得分:0)
问题出在您的查询的开头,
Select( Select ....
删除初始“选择(”并重试查询。运行
时Select (Select ..)
第二个选择只能返回一列(除非你连接返回的数据)。