SELECT DT.TenantDescription
,DT.PropertyNumber
,DT.UnitNo
,DT.AdressLn1
,DT.AddressLn2
,DT.AddressSituation
,(
CASE
WHEN DT.TransactionCode = 1
THEN DT.New_TransactionValue
ELSE 0
END
) AS RentDue
,(
CASE
WHEN DT.TransactionCode = 2
THEN DT.New_TransactionValue
ELSE 0
END
) AS OTHERSUMSDUE
,(
CASE
WHEN DT.TransactionCode = 3
THEN DT.New_TransactionValue
ELSE 0
END
) AS ARREARSBFWD
,(
CASE
WHEN DT.TransactionCode = 4
THEN DT.New_TransactionValue
ELSE 0
END
) AS ARREARSCFWD
,(
CASE
WHEN DT.TransactionCode = 5
THEN DT.New_TransactionValue
ELSE 0
END
) AS IRRECOVERABLERENT
,(
CASE
WHEN DT.TransactionCode > 5
THEN DT.New_TransactionValue
ELSE 0
END
) AS Expenditure
FROM (
SELECT * * (
SELECT New_TenantNameOnly
FROM New_Rentmaster Rm
WHERE Rm.New_rentmasterId = PD.new_rentmasterid
) AS TenantDescription
,* * (
SELECT [New_UnitNumber]
FROM new_propertyunits NPU
WHERE NPU.[New_propertyunitsId] = PD.[new_unitnumberid]
) AS UnitNo
,(
SELECT New_AddressLine1
FROM New_address
WHERE New_addressId = (
SELECT New_addressid
FROM New_PropertyMaster PM
WHERE PM.new_propertymasterid = PD.[new_propertynumbernameid]
)
) AS AdressLn1
,(
SELECT New_AddressLine2
FROM New_address
WHERE New_addressId = (
SELECT New_addressid
FROM New_PropertyMaster PM
WHERE PM.new_propertymasterid = PD.[new_propertynumbernameid]
)
) AS AddressLn2
,(
SELECT TT.[New_TransactionTypeCode] AS TransactionCode
FROM New_transactiontype TT
WHERE [New_transactiontypeId] = PD.[new_transactioncodenameid]
) AS TransactionCode
,(
SELECT New_PropertyNumber
FROM New_PropertyMaster PM
WHERE PM.new_propertymasterid = PD.[new_propertynumbernameid]
) AS PropertyNumber
,(
SELECT New_UnitAddressIdName
FROM New_propertyunits NPU
WHERE NPU.[New_propertyunitsId] = PD.[new_unitnumberid]
) AS AddressSituation
,PD.New_TransactionValue
FROM New_PropertyDetails PD
) AS DT
上面的代码工作正常
现在我想对上面的列进行更改(名称别名为TenantDescription
),我想用下面的代码替换上面的列
Select New_TenantNameOnly from New_Rentmaster Rm
New_TenantNumber IN
(Select MAX(New_TenantNumber) from new_rentmaster GROUP BY [New_Unit_No],[New_Propety_Number])
然后它给了我一个错误
子查询返回多个值
此代码应该返回多个值
那我该怎么办>??