uniqueidentifier与int错误不兼容

时间:2011-06-15 15:45:14

标签: stored-procedures

这是我的存储过程中的Select语句,我试图根据用户输入的开始日期获取所有案例。我一直在'uniqueidentifier与int不兼容'。不知道该怎么做。

(
            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

1 个答案:

答案 0 :(得分:0)

CaseID是uniqueidentifier,你使用COUNT(DISTINCT C.CaseID)UNION这将是int

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

因此会出现此错误。你在第一个条款中需要COUNT吗?