I have a SQL Function like this;
ALTER FUNCTION [dbo].[fngcodeme]
(
@HESAP INT, @DOV INT, @TEKLIF VARCHAR(10)
)
RETURNS FLOAT
AS
BEGIN
DECLARE @Result float
SET @Result = (SELECT SUM(TUTAR)
FROM YAZ..MARDATA.M_GHAREKET
WHERE TEMEL_HESAP = @HESAP
AND DOVIZ_KOD = @DOV
AND REF_KOD = 'GC'
AND BACAK_GRUP = 'PERT'
AND ISL_KOD = 1
AND ACIKLAMA LIKE '% + @TEKLIF + %''')
RETURN @Result
END
This is perfectly work.
This SQL
also work. Result is 18587.73
SELECT SUM(TUTAR)
FROM YAZ..MARDATA.M_GHAREKET
WHERE TEMEL_HESAP = 1252
AND DOVIZ_KOD = 21
AND REF_KOD = 'GC'
AND BACAK_GRUP = 'PERT'
AND ISL_KOD = 1
AND ACIKLAMA LIKE '%S08-2/334%'
But when i want to start this function with parameters in SQL Server
;
SELECT dbo.fngcodeme(1252, 21, 'S08-2/334')
Result is getting NULL
.
I don't understand what i'm开发者_高级运维 doing wrong..!
Anyone idea??
Need to to fix the @TEKLIF filter
AND ACIKLAMA LIKE '%' + @TEKLIF + '%'
You are actually searching for this value currently
% + @TEKLIF + %'
AND ACIKLAMA LIKE '% + @TEKLIF + %''')
Should read
AND ACIKLAMA LIKE '''%' + @TEKLIF + '%''')
精彩评论