gpt4 book ai didi

c# - sql "LIKE"查询语法

转载 作者:行者123 更新时间:2023-11-30 21:20:01 26 4
gpt4 key购买 nike

这个查询有什么问题?

string command_get_pay = "select Credit 
from Update_Company_Credit
where (Update_Date LIKE '%" +
System.DateTime.Today.ToShortDateString() + "%')";

最佳答案

我相信您正在尝试检查 Update_date 是否为当前日期,而不考虑时间,并且您的问题是即使当前日期有一些 Update_date 值,您也没有收到任何结果。

这是因为 System.DateTime.Today.ToShortDateString() 将系统日期转换为与将日期时间隐式转换为由 LIKE 比较生成的字符串所使用的格式不同的格式。

鉴于 SQLServer 有自己的日期比较功能,我建议您使用它们,如下所示:

string command_get_pay = "select Credit 
from Update_Company_Credit
where (datediff(d,Update_Date, getdate())=0)";

关于c# - sql "LIKE"查询语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3508024/

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