2011-06-15 87 views
0

這是我的存儲過程中的Select語句,我試圖根據用戶輸入的開始日期來獲取所有的情況。我不斷收到'uniqueidentifier與int不兼容'。不知道如何去做。uniqueidentifier與int error不兼容

(
      SELECT COUNT(DISTINCT C.CaseID) 
      FROM [Case] C 
      INNER JOIN CaseOffice COD ON C.CaseId = COD.CaseId 
      INNER JOIN Office OD ON COD.OfficeId = OD.OfficeId 
      WHERE C.DateCreated <= @BeginDate AND OD.OfficeId = O.OfficeId 
      AND C.CaseId NOT IN 
      (
       SELECT CaseId 
       FROM CaseStatusChange CSC 
       WHERE CSC.DateClosed < @BeginDate 
      ) 
      UNION 
      SELECT ReOpened.CaseId FROM 
      (
       SELECT C.CaseId, MAX(CSC.DateReopened) AS DateReOpened 
       FROM [Case] C 
       INNER JOIN [CaseStatusChange] CSC ON C.CaseId = CSC.CaseId 
       WHERE CSC.DateReopened <= @BeginDate 
       GROUP BY C.CaseId 
      ) ReOpened 
      WHERE ReOpened.CaseId NOT IN -- Wasn't reopened and closed 
      (
       SELECT CaseId FROM CaseStatusChange 
       WHERE CaseId = ReOpened.CaseId AND 
       CaseStatusChange.DateClosed BETWEEN ReOpened.DateReopened AND @BeginDate 
      ) 
     )AS OpenBeginCases 

回答

0

CaseID是唯一標識符,你UNION這與COUNT(DISTINCT C.CaseID),這將是int

... 
SELECT COUNT(DISTINCT C.CaseID) --int 
... 
UNION 
... 
SELECT ReOpened.CaseId --uniqueidentifier 
... 

所以這個錯誤可以預期。第一個條款中是否需要COUNT?

+0

我想根據開始日期來計算有多少個開放案例。我刪除了union,只是將它留作第一個count子句並執行它,但是所有列的返回值都是0. – Masriyah 2011-06-15 16:10:08

+0

您詢問了有關錯誤的信息:我告訴過您爲什麼會發生這種情況。計數爲零意味着您的查詢錯誤,這是一個*不同的問題:它的工作原理,沒有錯誤,只是錯誤的數據。 – gbn 2011-06-15 16:38:02

+0

謝謝你的幫助。 – Masriyah 2011-06-15 16:42:15

相關問題