如果等于或小于今天SQL

如果等于或小于今天SQL

本文介绍了如果等于或小于今天SQL Server CE,则从表中获取expiredate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一些帮助将不胜感激。

我有一个表tblItem与列ExpireDate(DateTime),AlertDays(Int)。

我插入的每个项目都有一个expiredate,我希望在过期前的x天内保持警惕。

我想计算今天所有的项目+ alertdays< = ExpireDate。

我有以下代码但是它导致错误:

解析查询时出错。 [令牌行号=  1 ,令牌行偏移=  48 ,令牌 in  error = 选择] 





 内部 静态  int  getAlertDateExpire()
{
SqlCeConnection con = ConectionAndData.Con;

if (con.State == System.Data.ConnectionState.Closed)
con.Open();

int number = 0 ;

string sqlCommand = 从tblItem中选择count(*)where(Getdate()+(从tblItem中选择AlertDays))as today< = ExpireDate;

SqlCeCommand com = new SqlCeCommand(sqlCommand,con);

尝试
{
number =( Int32 )com.ExecuteScalar();
}
catch (例外情况)
{
throw ex;
}
最后
{
con.Close();
}

返回号码;
}





我的尝试:



string sqlCommand =(从tblItem中选择count(*),其中DATEADD(day,(选择来自tblItem的AlertDays),Getdate())< = ExpireDate);

解决方案

Some help would be appreciated.
I have a table tblItem with columns ExpireDate (DateTime), AlertDays (Int).
Each Item I insert has an expiredate, I want to be alert in x days before the expiredate.
I want to count all the items where today + alertdays <= ExpireDate.
I have the following code but it is causing an error:

There was an error parsing the query. [ Token line number = 1,Token line offset = 48,Token in error = select ]



internal static int getAlertDateExpire()
{
    SqlCeConnection con = ConectionAndData.Con;

    if (con.State == System.Data.ConnectionState.Closed)
        con.Open();

    int number = 0;

    string sqlCommand = "select count(*) from tblItem where (Getdate()+(select AlertDays from tblItem)) As today <= ExpireDate";

    SqlCeCommand com = new SqlCeCommand(sqlCommand, con);

    try
    {
        number = (Int32)com.ExecuteScalar();
    }
    catch (Exception ex)
    {
        throw ex;
    }
    finally
    {
        con.Close();
    }

    return number;
}



What I have tried:

string sqlCommand = "(select count(*) from tblItem where DATEADD(day, (select AlertDays from tblItem) ,Getdate()) <= ExpireDate)";

解决方案


这篇关于如果等于或小于今天SQL Server CE,则从表中获取expiredate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 17:29