2011-03-15 47 views
0

在我SQL我有這樣共值,並且返回值在同柱

SUM(ISNULL(CAST(A.ODENEN_ANAPARA AS FLOAT),0)+ISNULL(CAST(A.FAIZ AS FLOAT),0)+ 
     ISNULL(CAST(A.BSMV AS FLOAT),0)+ISNULL(CAST(A.GECIKME_FAIZ AS FLOAT),0)+ 
     ISNULL(CAST(A.GECIKME_BSMV AS FLOAT),0)) AS 'YATAN' 

列和我有一個功能越來越像另一個值;

USE [Example] 
GO 
/****** Object: UserDefinedFunction [dbo].[fngcodeme] Script Date: 03/15/2011 11:52:16 ******/ 
SET ANSI_NULLS ON 
GO 
SET QUOTED_IDENTIFIER ON 
GO 

ALTER FUNCTION [dbo].[fngcodeme] 
(
    @HESAP INT,@BAS DATE, @BIT DATE,@DOV INT 
) 
RETURNS FLOAT 

AS 
BEGIN 

RETURN( 
    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 ISL_TAR >= @BAS 
    AND ISL_TAR <= @BIT 
) 
END 

我想要的是第一個SQL和函數在同一列上的總數。

(例: 「亞坦」 是A,函數返回值是B,我想要一個式柱A + B)

Best Regards, Soner

回答

1
select 
    SUM(ISNULL(CAST(A.ODENEN_ANAPARA AS FLOAT),0)+ISNULL(CAST(A.FAIZ AS FLOAT),0)+ 
     ISNULL(CAST(A.BSMV AS FLOAT),0)+ISNULL(CAST(A.GECIKME_FAIZ AS FLOAT),0)+ 
     ISNULL(CAST(A.GECIKME_BSMV AS FLOAT),0)) 
    + dbo.fngcodeme(@HESAP,@BAS,@BIT,@DOV) 
from ... 
+0

@BAS是開始日期,@BIT是完成日期。在我的頁面中,我爲這個日期選擇了兩個文本框。 (txtBoxText1!=「」){strQuery = strQuery +「AND A.ISL_TAR> = @S_TARIH_B」這個圖片http://i1103.hizliresim.com/2011/3/15/5030.jpg ; dt_stb = DateTime.Parse(txtBoxText1); myCommand.Parameters.AddWithValue(「@ S_TARIH_B」,dt_stb);}如果(txtBoxText2!=「」) {strQuery = strQuery +「AND A.ISL_TAR <= @S_TARIH_S」; dt_sts = DateTime.Parse(txtBoxText2); myCommand.Parameters.AddWithValue(「@ S_TARIH_S」,dt_sts);我如何設置它的功能? (開始,結束日期) – 2011-03-15 13:09:27

+0

由於此代碼不起作用,因此此代碼無效SUM(ISNULL(CAST(A.ODENEN_ANAPARA AS FLOAT),0)+ ISNULL(CAST(A.FAIZ AS FLOAT),0)+ ISNULL(CAST(A (CAST(A.GECIKME_BSMV AS FLOAT),0))+ [dbo]。[f編碼](@ B。 HESAP_NO,@S_TARIH_B,@S_TARIH_S,@ B.DOVIZ_KOD)AS'YATAN' – 2011-03-15 13:11:58