Getting value twice in SQL
I have a SQL
like this;
SELECT B.HESAP_NO, B.TEKLIF_NO1 + '/' + B.TEKLIF_NO2 AS 'TEKLIF',B.MUS_K_ISIM,
dbo.fngcodeme(B.HESAP_NO, B.DOVIZ_KOD, B.TEKLIF_NO1 + '/' + B.TEKLIF_NO2,'11/03/2011', '11/03/2011'),
(CASE WHEN B.DOVIZ_KOD = 21 THEN 'EUR' WHEN B.DOVIZ_KOD = 2 THEN 'USD' WHEN B.DOVIZ_KOD = 1 THEN 'TL' END) AS 'KUR',
D.AVUKAT,
(CASE WHEN D.HESAP IN (SELECT T_HESAP_NO FROM TAKIP) THEN
(SELECT ICRA_TAR FROM TAKIP WHERE T_HESAP_NO = D.HESAP)
ELSE ' ' END) AS 'ICRA TARİHİ',
(CASE WHEN D.HESAP IN (SELECT T_HESAP_NO FROM TAKIP) THEN
(SELECT HACIZ_TAR FROM TAKIP WHERE T_HESAP_NO = D.HESAP)
ELSE '' END) AS 'HACİZ TARİHİ'
FROM YAZ..MARDATA.S_TEKLIF B, AVUKAT D
WHERE B.HESAP_NO = D.HESAP
AND ISNULL(dbo.fngcodeme(B.HESAP_NO, B.DOVIZ_KOD, B.TEKLIF_NO1 + '/' + B.TEKLIF_NO2,'11/03/2011', '11/03/2011'),0) > 0
GROUP BY B.HESAP_NO, B.TEKLIF_NO1 + '/' + B.TEKLIF_NO2,B.DOVIZ_KOD ,B.MUS_K_ISIM, D.AVUKAT, D.HESAP
Here is my tables;
S_TEKLIF (B) AVUKAT TAKIP
HESAP_NO (PK) HESAP(PK) T_HESAP_NO (PK)
TEKLIF_NO1 MUS_K_ISIM ICRA_TAR
TEKLIF_NO2 AVUKAT HACIZ_TAR
MUS_K_ISIM
DOVIZ_KOD
And here is mine dbo.fngcodeme
Function;
ALTER FUNCTION [dbo].[fngcodeme]
(
@HESAP INT, @DOV INT, @TEKLIF VARCHAR(10), @BAS VARCHA开发者_Go百科R(10), @BIT 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 + '%'
AND ISL_TAR >= CONVERT(DATETIME, + '' + @BAS + '',103)
AND ISL_TAR <= CONVERT(DATETIME, + '' + @BIT + '',103)
)
RETURN @Result
END
My top SQL
is working perfect but gettin two value with the same data.
Where the error i could be doing?
Best Regards,
Soner
It is not the same, the TEKLIF
column differs. You group on that column, hence you will get two results of they differ.
精彩评论