简体   繁体   English

根据开始日期和结束日期从MSSQL表中获取数据

[英]Getting data from mssql table based on startdate and enddate

I am writing a query to select data from a table called contest. 我正在编写一个查询,以从称为竞赛的表中选择数据。 each contest has start date and enddate. 每个比赛都有开始日期和结束日期。 I want to select all the contest details from the contest table if the current date is between start date and end date. 如果当前日期在开始日期和结束日期之间,我想从比赛表中选择所有比赛详细信息。

select * from contest 
where getDate() between startdate and enddate

getDate() returns you the current date and time. getDate()返回您当前的日期和时间。

select * from contest
where dtBegin <= getDate() and getDate() <= dtEnd

out of interest why is this tagged c# what are you trying to achieve with this? 出于兴趣,为什么要使用此标记的c#来实现这一目标?

if your trying to get this into an app some how you could use either a SqlDataReader or LinqtoSQL (plus others) 如果您尝试将其导入应用程序中,请使用SqlDataReader或LinqtoSQL(以及其他方法)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM