2010-12-11 20 views
0

Possible Duplicate:
WHERE Something IN (CASE WHEN statement) ??!!WHERE etwas IN (CASE WHEN Anweisung)?

ich will ro ein "select-where" cluase mit cinditonal Zustand schreiben.
i "Fall-wenn" in "wo ID IN" Klausel verwendet, aber ich habe die folgende Fehlermeldung:

Msg 512, Level 16, State 1, Line 1 
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. 

hier ist mein vereinfachten Code:

SELECT 
    UnitsAllocation.UnitID, 
    OrganizationUnits.Title AS UnitTitle, 
    'Title' AS ExpenseTitle1, 
    SUM(UnitsAllocationDetails1.ExpenseAmount1) AS ExpenseAmount1 
FROM 
    [bdg_UnitsAllocation] UnitsAllocation LEFT OUTER JOIN 
(SELECT 
      UnitsAllocationDetails.UnitsAllocationID, 
      SUM(UnitsAllocationDetails.Amount)/1 AS ExpenseAmount1 
    FROM [bdg_UnitsAllocationDetails] UnitsAllocationDetails 
    WHERE UnitsAllocationDetails.ExpenseID IN (CASE 1 
                WHEN 1 THEN (SELECT Id FROM bdg_Expenses WHERE ParentId = 1) 
                ELSE (SELECT Id FROM bdg_Expenses WHERE Id = 1) 
               END) 

    GROUP BY UnitsAllocationDetails.UnitsAllocationID) UnitsAllocationDetails1 ON UnitsAllocationDetails1.UnitsAllocationID = UnitsAllocation.ID LEFT OUTER JOIN 
    [bdg_OrganizationUnits] OrganizationUnits ON UnitsAllocation.UnitID = OrganizationUnits.ID 
GROUP BY UnitsAllocation.UnitID, OrganizationUnits.Title 

Bitte schauen Sie auf "WHERE UnitsAllocationDetails.ExpenseID IN ... "
Wie kann ich das beheben?

+0

Sie haben gerade die gleiche Frage gestellt. Wenn Sie Ihre Frage ändern möchten, bearbeiten Sie sie, erstellen Sie keine neue Frage. –

+1

leider in meiner Region "XXX" ist verboten pharase! und wurde gemäß unseren Internet-Richtlinien gefiltert. damit ich meine Frage nicht öffnen kann, um sie anzusehen oder zu bearbeiten, habe ich sie erneut gefragt. Du hast XXX nochmal auf dieser Seite wiederholt! – mahdiahmadirad

+0

rotfl. Ich habe Ihre ursprüngliche Frage bearbeitet, um die x zu entfernen. –

Antwort

0

Statt

WHERE UnitsAllocationDetails.ExpenseID IN (Fall 1 WHEN 1 THEN (SELECT-ID aus bdg_Expenses WHERE ParentId = 1) ELSE (SELECT-ID aus bdg_Expenses WHERE ID = 1) END) verwenden die folgende

WHERE UnitsAllocationDetails.ExpenseID IN (SELECT-ID aus bdg_Expenses WHERE ParentId = 1 und 1 = 1 UNION ALL SELECT-ID aus bdg_Expenses WHERE ID = 1 und 1 <> 1 )

+0

sehr nützliche Weise – mahdiahmadirad