Msg 512,Level 16,State 1,Line 2子查询返回的值超过1。这是不允许的 当子查询跟随=,!=,<,< =,>,> =或子查询用作表达式时。
(从Ware.dbo.Dimf中选择LocationId,其中t.OriginalLocationId = l.LocationId和t.CompanyId = l.CompanyId)作为LocationId ,CASE WHEN(从Ware.dbo.DimU ut中选择UnitTypeId,其中t.unit_type = ut.UnitType)IS NULL那么9999 ELSE (从Ware.dbo.DimU ut中选择UnitTypeId,其中t.unit_type = ut.UnitType)END作为UnitTypeId ,CASE WHEN(从Ware.dbo.Dimc f中选择FirmwareId,其中t.FirmwareVersion = f.Firmware和t.CompanyId = f.CompanyId)IS NULL那么9999 其他 (从Ware.dbo.Dimc f中选择FirmwareId,其中t.FirmwareVersion = f.Firmware和t.CompanyId = f.CompanyId) 结束 作为FirmwareId ,ISNULL(t.Installs,0)as Installs
,AddDate = GETDATE() 来自#Temp2 t where(从Ware.dbo.Dimf中选择LocationId,其中t.OriginalLocationId = l.LocationId和t.CompanyId = l.CompanyId)不为null 按LocationId排序
答案 0 :(得分:1)
曾经听说过Joins .......也许会尝试像......
Select l.LocationId as LocationId
, ISNULL(ut.UnitTypeId, 9999) as UnitTypeId
, ISNULL(f.FirmwareId , 9999) as FirmwareId
, ISNULL(t.Installs,0) as Installs
, GETDATE() as AddDate
from #Temp2 t
LEFT JOIN Ware.dbo.Dimf l ON t.OriginalLocationId = l.LocationId
and t.CompanyId = l.CompanyId
LEFT JOIN Ware.dbo.DimU ut ON t.unit_type = ut.UnitType
LEFT JOIN Ware.dbo.Dimc f ON t.FirmwareVersion = f.Firmware
and t.CompanyId = f.CompanyId
where l.LocationId is not null
Order by l.LocationId