您好我收到此错误:
当不使用 EXISTS 引入子查询时,选择列表中只能指定一个表达式。
这是我当前的 SQL 查询:
DECLARE @UgpEntry VARCHAR(50)
SELECT @UgpEntry = UgpEntry FROM OITM t1 WHERE t1.ItemCode='CID-11418272385'
IF (@UgpEntry = -1)
SELECT
t1.ItemCode as sapitemcode
, t1.CodeBars as Barcode
, t1.ItemName as description
,LEFT(t1.ItemName,20) as short_description
,
(select max(p.Price)
from ITM1 p
where p.ItemCode = t1.ItemCode
and p.PriceList = 1) as [price_1]
,
(SELECT T0.[ItemCode], T2.[U_NAME] as 'User that created Item', t0.updatedate
FROM AITM T0 inner join OUSR T2 on t0.usersign = t2.internal_K
WHERE T0.[ItemCode] = t1.ItemCode
group by T0.[ItemCode], T2.[U_NAME], t0.loginstanc, t0.updatedate
having t0.loginstanc = (select min(loginstanc) from AITM where itemcode = t0.loginstanc)),
CASE t1.VatGourpSa when 'V0' THEN 4 when 'V1' THEN 1 WHEN 'V2' THEN 2 WHEN 'V3' THEN 3 END as TaxCode,t1.U_GRUPOA, t1.U_GRUPOB, t1.U_GRUPOC, t1.UgpEntry
FROM OITM t1
WHERE t1.ItemCode='CID-11418272385'
ELSE
SELECT t1.ItemCode as sapitemcode
, t1.CodeBars as Barcode
, t1.ItemName as description
,LEFT(t1.ItemName,20) as short_description
, (select max(p.Price)
from ITM9 p
where p.ItemCode = t1.ItemCode
and p.UomEntry = 1 and p.PriceList = 1) as [price_1mananitas],
(select max(p.Price)
from ITM1 p
where p.ItemCode = t1.ItemCode
and p.PriceList = 1) as [preciocajamananitas],
(select max(p.Price)
from ITM9 p
where p.ItemCode = t1.ItemCode
and p.UomEntry = 1 and p.PriceList = 2) as [price_2cabra],
(select max(p.Price)
from ITM1 p
where p.ItemCode = t1.ItemCode
and p.PriceList = 2) as [preciocajacabra]
, CASE t1.VatGourpSa when 'V0' THEN 4 when 'V1' THEN 1 WHEN 'V2' THEN 2 WHEN 'V3' THEN 3 END as TaxCode,t1.U_GRUPOA, t1.U_GRUPOB, t1.U_GRUPOC, t1.UgpEntry
FROM OITM t1
WHERE t1.ItemCode='CID-11418272385'
我刚刚添加了这个子查询:
(SELECT T0.[ItemCode], T2.[U_NAME] as 'User that created Item', t0.updatedate
FROM AITM T0 inner join OUSR T2 on t0.usersign = t2.internal_K
WHERE T0.[ItemCode] = t1.ItemCode
group by T0.[ItemCode], T2.[U_NAME], t0.loginstanc, t0.updatedate
having t0.loginstanc = (select min(loginstanc) from AITM where itemcode = t1.ItemCode))
当我单独运行它时,我会得到这样的结果:
我想要做的是在我的主查询中添加该选择,以便在原始查询中显示为新列。所以它应该像这样在末尾出现新列(T2.[U_NAME] 和 t0.updatedate):
我错过了什么?
谢谢你
用过的: