嵌套的select语句

时间:2012-06-04 13:26:46

标签: stored-procedures

我试图根据大小超过0的情况返回结果,但是当我尝试执行存储过程时,我得到一个错误说明:操作数类型冲突:uniqueidentifier与tinyint不兼容。这是我在where子句中的嵌套select语句。

SELECT 
      O.OfficeId,
      O.OfficeName AS Name,
      AT.Description AS CaseActivity,
      SUM(A.Duration) AS [CaseMinutes], 
      CAST(SUM(A.Duration) AS FLOAT) / 60 AS [CaseHours],  
      COUNT(A.ActivityId) AS Activities,
      COUNT(DISTINCT A.CaseId) AS Cases,
      MIN(CAST(A.Duration AS FLOAT) / 60) AS [Case Min Time],
      MAX(CAST(A.Duration AS FLOAT) / 60) AS [Case Max Time],
      SUM(CAST(A.Duration AS FLOAT) / 60) / COUNT(A.ActivityId) AS [Case Avg Time],
      SUM(CAST(A.Duration AS FLOAT) / 60) AS [Case TotalHours]
  FROM Activity A
      INNER JOIN ActivityType AT ON A.ActivityTypeId = AT.ActivityTypeId
      INNER JOIN ActivityEntry AE ON A.ActivityEntryId = AE.ActivityEntryId
      INNER JOIN [Case] C ON A.CaseId = C.CaseId
      INNER JOIN [Office] O ON AE.OfficeId = O.OfficeId
      INNER JOIN [User] U ON C.CreatedByUserId = U.UserId
  WHERE  A.CaseId in(select A.CaseId from Activity where A.CaseId > 1 AND .dbo.DateOnly(AE.ActivityDate) BETWEEN @BeginDate AND @EndDate)
  GROUP BY 
        O.OfficeId,
        O.OfficeName,
        AT.Description

**所需的GOAL来自存储过程* *
我想返回此存储过程的结果,其中案例计数大于0.目前,此存储过程返回案例为0或更大的所有活动。我只对获取案例大于0的活动感兴趣。在我的where子句中,我试图插入另一个选择语句,将结果过滤到案例> 0.

1 个答案:

答案 0 :(得分:0)

错误消息告诉您

其中一项比较是比较两列不同类型的东西。

查看表结构并查看您要比较的哪些列具有唯一标识符,哪些列具有整数,然后查看sql并查看您正在比较哪些列。