在期望条件的上下文中指定的非布尔类型的表达式,在')'附近。错误

时间:2014-06-28 12:35:19

标签: sql sql-server sql-server-2008 function

ALTER FUNCTION [dbo].[TabloGetir] (@id  INT,
                                   @ay  INT,
                                   @yil INT)
RETURNS TABLE
AS
    RETURN
      (SELECT ARACKM_ARAC_ID,
              ARACKM_ID,
              ARACKM_TARIHI,
              ARACKM_KM,
              A_PLAKA,
              A_ID
       FROM   VARACKM
       WHERE  A_ID = @id
              AND MONTH(ARACKM_TARIHI) = @ay
              AND YEAR(ARACKM_TARIHI) = @yil) 

这是我的表值函数,我一直有这个错误,有人可以帮助我吗?

这就是我所说的:

comm2 = New SqlCommand(@"select ARACKM_TARIHI, SUM(ARACKM_KM) AS TUTAR 
                         from VARACKM 
                         GROUP BY ARACKM_TARIHI 
                         HAVING [dbo].[TabloGetir](@A_ID,@ay,@yil) ",conn2)

comm2.Parameters.Add("@A_ID", plakaId)  
comm2.Parameters.Add("@ay", ay)
comm2.Parameters.Add("@yil", yil)
reader2 = comm2.ExecuteReader()

1 个答案:

答案 0 :(得分:1)

问题是having条款。

HAVING [dbo].[TabloGetir](@A_ID,@ay,@yil) 

首先,您的函数返回一个表,having子句需要一个带有某种比较的标量。其次,你没有比较。也许你的意思是:

HAVING EXISTS (select 1 from [dbo].[TabloGetir](@A_ID,@ay,@yil) )