2016-11-10 6 views
-4

Msg 512, Ebene 16, Status 1, Zeile 2 Die Unterabfrage hat mehr als 1 Wert zurückgegeben. Dies ist nicht zulässig , wenn die Unterabfrage folgt =,! =, <, < =,>,> = oder wenn die Unterabfrage als Ausdruck verwendet wird.Nachricht 512, Ebene 16, Status 1, Zeile 2 Unterabfrage gab mehr als 1 Wert zurück. Dies ist nicht zulässig

(Select LocationID aus Ware.dbo.Dimf L wobei t.OriginalLocationId = l.LocationId und t.CompanyId = l.CompanyId) als LocationID , CASE WHEN (Wählen von UnitTypeId Ware.dbo.DimU ut wo t. unit_type = ut.UnitType) IS NULL THEN 9999 ELSE (Wählen Sie UnitTypeId aus Ware.dbo.DimU ut wobei t.unit_type = ut.UnitType) END als UnitTypeId , CASE WHEN (Wählen Sie FirmwareId aus Ware.dbo.Dimc f wobei t .FirmwareVersion = f.Firmware und t.CompanyId = f.CompanyId) IST NULL THEN 9999 ELSE (Wählen Sie FirmwareId aus Ware.dbo.Dimc f wobei t.FirmwareVersion = f.Firmware und t.CompanyId = f.CompanyId) ENDE als FirmwareId , ISNULL (t.Installs, 0) als Installiert

, AddDate = GETDATE() von # Temp2 t wo (Select LocationID von Ware.dbo.Dimf l wo t.OriginalLocationId = l.LocationId und t.CompanyId = l.CompanyId) nicht null ist Bestellen von LocationID

+7

Ja, und was ist die Frage? – jarlh

+2

Was ist unklar an der Fehlermeldung? –

+0

Ich frage, ob Sie beim Umschreiben der Abfrage helfen könnten – ALE

Antwort

1

Schon mal was von Joins gehört ....... vielleicht versuchen, so etwas wie .....

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 
Verwandte Themen