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()
答案 0 :(得分:1)
问题是having
条款。
HAVING [dbo].[TabloGetir](@A_ID,@ay,@yil)
首先,您的函数返回一个表,having
子句需要一个带有某种比较的标量。其次,你没有比较。也许你的意思是:
HAVING EXISTS (select 1 from [dbo].[TabloGetir](@A_ID,@ay,@yil) )