我有這樣在SQL功能使用IF 2表
BAS焦油的頁面。 - >Start Date
位。焦油 - >End Date
我有一個SQL
這樣這個頁面,
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,'01/01/2011', '11/03/2011') AS 'YATAN',
(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 CONVERT(VARCHAR(10),ICRA_TAR,103) 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 CONVERT(VARCHAR(10),HACIZ_TAR,103) 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 B.KAPANIS_TAR IS NULL
AND ISNULL(dbo.fngcodeme(B.HESAP_NO, B.DOVIZ_KOD, B.TEKLIF_NO1 + '/' + B.TEKLIF_NO2,'01/01/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
,這是我dbo.fngcodeme
功能,
ALTER FUNCTION [dbo].[fngcodeme]
(
@HESAP INT, @DOV INT, @TEKLIF VARCHAR(10), @BAS VARCHAR(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
我想是
IF `Bit. Tar. (End Date)` is less or equal then 28/02/2011 --> Use M_HAREKET(table)
IF Baş. Tar. (Start Date) is great or equal then 01/03/2011 --> Use M_GHAREKET(table)
我該怎麼做?
我應該改變SQL
還是Function
?哪一個?
你有兩個條件不是免費的。如果結束日期> 28/2並且開始日期<28/2,該怎麼辦?你的2件不包括它 – RichardTheKiwi 2011-03-16 22:20:46
@理查德這沒關係這個網頁。 「用戶」將僅輸入..... - 2011年2月28日或2011年3月1日 - 日期範圍。 – 2011-03-17 06:09:15