获取2个日期之间的值C#/ SQL语句

时间:2016-05-16 04:58:14

标签: c# sql

我正在尝试检索Employee_Share,Entity_Share,Government_Share。

当用户输入Start_PeriodEnd_Period哪个数据类型时,我希望获取此日期之间的特定份额。此外,在某些情况下,问题是我的数据库中End_Period的值为null。我想要选择查询的任何帮助:

示例:我的数据库

Start_period    End_Period   Employee_Share   Entity_Share  Government_Share
----------------------------------------------------------------------------
01/01/1994       01/01/1998      0.7              0.14           0.17
12/03/1998       null            0.7               0               0
11/01/2011       09/09/2013      0.8               0              0.9

我正在尝试使用C#:

string ReadShare = "select EMPLOYEE_SHARE, GOVERMENT_SHARE, ENTITY_SHARE, END_PERIOD";
ReadShare = ReadShare + " from cpms.UNPAID_LEAVES_RUALES where";
ReadShare = ReadShare + " TYPE = " + rsnew["LEAVE_TYPE"].ToString();
ReadShare = ReadShare + " and PAY_OPTION = " + rsnew["LEAVE_PAY_OPTION"].ToString();
ReadShare = ReadShare + " and REASON = " + rsnew["LEAVE_REASON"].ToString();
ReadShare = ReadShare + " and START_PERIOD <= '" + Convert.ToDateTime(rsnew["FROM_DATE"].ToString()).ToString("dd/MM/yyyy") + "'";
ReadShare = ReadShare + " and (END_PERIOD is null OR ('" + Convert.ToDateTime(rsnew["FROM_DATE"].ToString()).ToString("dd/MM/yyyy") + "' <= nvl(END_PERIOD, '01/01/2500')))";

0 个答案:

没有答案