SQL月度报告甚至在不同的年份也显示出来

问题描述 投票:0回答:1

我收到了来自我的数据库的访客的月度报告,其中我有一个只显示月份和年份的日期时间选择器(MM / yyyy)代码正在运行,但问题是它甚至在不同年份也有效。

var FirstDayOfMonth = new DateTime(dtpMonth.Value.Year, dtpMonth.Value.Month, 1);
var LastDayOfMonth = FirstDayOfMonth.AddMonths(1).AddDays(-1);
SqlCommand cmd = new SqlCommand("SELECT ISNULL(SUM(Male),0) as Male,ISNULL(SUM(Female),0)  as Female ,ISNULL(SUM(Pax),0)  as Pax,ISNULL(SUM(Single),0)  as Single,ISNULL(SUM(Married),0)  as Married,ISNULL(SUM(Students),0)  as Students,ISNULL(SUM(Elementary),0)  as Elementary,ISNULL(SUM(Highschool),0)  as Highschool, ISNULL(SUM(College),0)  as College,ISNULL(SUM(PWD),0)  as PWD, ISNULL(SUM([AR Users]),0)  as ARUsers,ISNULL(SUM([12 Below]),0)  as age1,ISNULL(SUM([13-21]),0)  as age2,ISNULL(SUM([22-35]),0)  as age3,ISNULL(SUM([36-50]),0)  as age4,ISNULL(SUM([51-65]),0)  as age5,ISNULL(SUM([65 Above]),0)  as age6 FROM  [tbl_Registration] where [Date Added] BETWEEN '"
        + FirstDayOfMonth.ToShortDateString() + "' AND  '" + LastDayOfMonth.ToShortDateString() + "'  ;", connection);

问题

如果我将年份改为09年,那么输出与09/2018相同。我在加载数据之前清除标签,所以不是问题。

2018 2017

sql-server
1个回答
0
投票

更新我真笨!我的数据类型是在varchar中。

© www.soinside.com 2019 - 2024. All rights reserved.