私が得る完全なエラーは次のとおりです。
メッセージ 512、レベル 16、状態 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