开发者

SQL Function Error

开发者 https://www.devze.com 2023-02-17 07:30 出处:网络
I have a SQL Function like this; ALTER FUNCTION [dbo].[fngcodeme] ( @HESAP INT, @DOV INT, @TEKLIF VARCHAR(10)

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 + '%''')
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号