我得到的完整错误是:
消息 512,级别 16,状态 1,第 1 行
子查询返回超过 1 个值。当子查询跟随 =、!=、<、<=、>、>= 或子查询用作表达式时,这是不允许的。
我通过了这个过去可以工作的 SQL 代码,我需要修复它,但我得到了上面的错误,但即使我注释掉某些部分,错误仍然保持不变
这是sql代码:
SELECT
OrderId = OrdNameAdd.ORDERS_ID,
LTRIM(ISNULL(OrdNameAdd.OBY_FirstName, '') + ' ' + ISNULL(OrdNameAdd.OBY_LASTNAME, '')) AS OrderedByName,
ObyVar1 = (SELECT varfld_value FROM MAILERVBL WHERE OBYMAILER = MAILERVBL.MAILER_SEQID AND VARDEF_SEQUENCE = 1),
ObyVar2 = (SELECT varfld_value FROM MAILERVBL WHERE OBYMAILER = MAILERVBL.MAILER_SEQID AND VARDEF_SEQUENCE = 2),
ObyVar3 = (SELECT varfld_value FROM MAILERVBL WHERE OBYMAILER = MAILERVBL.MAILER_SEQID AND VARDEF_SEQUENCE = 3),
ExtendedDefaultValue = (SELECT sum(isnull(p.prduct_value,0) * (isnull(pickdt.prdord_toshipqty,1)))
FROM PICKDT
LEFT OUTER JOIN
locVerBals ON PICKDT.PRVERS_SEQID = locVerBals.PRVERS_Seqid
LEFT OUTER JOIN
LOCPRDSUM p ON locVerBals.PRDUCT_Seqid = p.PRDUCT_SEQID
AND p.system_id = PICPAK.SYSTEM_ID
WHERE
PICKDT.PICPAK_Seqid = PICPAK.PICPAK_Seqid
AND p.PRDUCT_INACTIVEDATE IS NULL),
FulfCharges = (rpt_BD.Linesshipped * ACCDEF_ChargePerLine) + ACCDEF_ChargePerShipment,
PubFreight = (rpt_BD.PubFreight),
TotalValue =
(SELECT
sum(isnull(p.prduct_value, 0) * (isnull(pickdt.prdord_toshipqty, 1)))
from PICKDT
LEFT OUTER JOIN locVerBals ON PICKDT.PRVERS_SEQID = locVerBals.PRVERS_Seqid
LEFT OUTER JOIN LOCPRDSUM p ON locVerBals.PRDUCT_Seqid = p.PRDUCT_SEQID
AND p.system_id = PICPAK.SYSTEM_ID
WHERE
PICKDT.PICPAK_Seqid = PICPAK.PICPAK_Seqid AND p.PRDUCT_INACTIVEDATE IS NULL)
+ isnull((rpt_BD.Linesshipped * ACCDEF_ChargePerLine), 0)
+ isnull(ACCDEF_ChargePerShipment,0) + isnull((rpt_BD.PubFreight), 0)
FROM
PICPAK
LEFT OUTER JOIN
ORDSTO ON PICPAK.ORDSTO_Seqid = ORDSTO.ORDSTO_Seqid
LEFT OUTER JOIN
OrdNameAdd ON ORDSTO.ORDERS_Seqid = OrdNameAdd.ORDERS_SEQID
LEFT OUTER JOIN
Rpt_BillingDetail rpt_BD ON PICPAK.PICPAK_Seqid = rpt_BD.PICPAK_Seqid
---------------hERE
WHERE
(convert(datetime, DateShipped, 1) >= '4/17/2012'
AND convert(datetime, DateShipped, 1) <= '12/17/2012')
---------------HERE
AND (PICPAK.PICPAK_Status = 'Complete' OR PICPAK.PICPAK_Status = 'Shipped'
OR picpak_Status = 'Voided')
/*AND (p.PRDUCT_INACTIVEDATE IS NULL)*/
AND ISNULL(PICPAK.SUPPLR_SEQID,0) = 0
GROUP BY
OrdNameAdd.ORDERS_ID,
OrdNameAdd.OBY_FirstName,
OrdNameAdd.OBY_LASTNAME,
OrdNameAdd.obymailer,
PICPAK.PICPAK_Seqid,
PICPAK.System_Id,
rpt_BD.PubFreight,
ACCDEF_ChargePerLine,
ACCDEF_ChargePerShipment,
rpt_BD.Linesshipped,
rpt_BD.Numpackages,
ordsto.orders_seqid
ORDER BY
ordsto.orders_seqid ASC