gpt4 book ai didi

c# - SQL 查询分隔日期

转载 作者:行者123 更新时间:2023-11-30 22:41:01 25 4
gpt4 key购买 nike

我有一个像这样工作的 sql。

SELECT  B.HESAP_NO, A.TEKLIF_NO1 + '/' + A.TEKLIF_NO2 AS 'TEKLIF',
B.MUS_K_ISIM, CONVERT(VARCHAR(10),A.ISL_TAR,103) AS 'TARIH',
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',
(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, CONVERT(VARCHAR(10),C.ICRA_TAR,103) AS 'İCRA TARİHİ', CONVERT(VARCHAR(10),C.HACIZ_TAR,103) AS 'HACİZ TARİHİ'

FROM YAZ..MARDATA.BIR_TAHSIL A, YAZ..MARDATA.S_TEKLIF B, TAKIP C, AVUKAT D, P_TAKIP_SR E

WHERE A.TEKLIF_NO1 = B.TEKLIF_NO1
AND A.TEKLIF_NO2 = B.TEKLIF_NO2
AND B.HESAP_NO = D.HESAP
AND D.HESAP = A.HESAP_NO

我用这样的代码添加了一个日期范围。

if (txtBoxText1 != "")
{
strQuery = strQuery + " AND A.ISL_TAR >= @S_TARIH_B";

dt_stb = DateTime.Parse(txtBoxText1);
myCommand.Parameters.AddWithValue("@S_TARIH_B", dt_stb);
}

if (txtBoxText2 != "")
{
strQuery = strQuery + " AND A.ISL_TAR <= @S_TARIH_S";
dt_sts = DateTime.Parse(txtBoxText2);
myCommand.Parameters.AddWithValue("@S_TARIH_S", dt_sts);
}

最后我添加GROUP BY

GROUP BY  B.HESAP_NO, A.TEKLIF_NO1 + '/' + A.TEKLIF_NO2,A.ISL_TAR,B.DOVIZ_KOD, B.HESAP_NO, B.MUS_K_ISIM, D.AVUKAT, C.ICRA_TAR, C.HACIZ_TAR

但是这个查询gettig结果例如像这样(部分)

HESAP_NO       MUS_K_ISIM     YATAN  Date
889 2M LOJİSTİK 7090 28/03/2010

2010 年 3 月 28 日刚刚获得一项记录。但是在数据库中,在这个日期,有两条记录。

HESAP_NO       MUS_K_ISIM     YATAN  Date
889 2M LOJİSTİK 5000 28/03/2010
889 2M LOJİSTİK 2090 28/03/2010

如您所见,(5000 + 2090 = 7090) 将所有 YATAN(数字)相加并获得一条记录作为顶部查询。

我想要的是,像第二个结果一样获取同一日期的所有记录。

  HESAP_NO     MUS_K_ISIM     YATAN  Date
889 2M LOJİSTİK 5000 28/03/2010
889 2M LOJİSTİK 2090 28/03/2010

我该怎么做?

祝好,索纳

最佳答案

这是因为您的 SELECT 中的 SUM 函数:

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',

尝试将其替换为:

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',

这也意味着您应该能够删除 GROUP BY 子句。这应该为您提供表格中任何唯一结果的结果。

关于c# - SQL 查询分隔日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4954040/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com