简体   繁体   English

日期比较,以检查最后一个日期是否已过去

[英]date comparison to check if last date has passed

I have a DB table with the following columns 我有一个包含以下列的数据库表

  1. PolicyNumber 保单号码
  2. NextPremiumDate 下一个PremiumDate
  3. PremiumNumber 保费号码

Example

For each PolicyNumber i have 5 NextPremiumDates . 对于每个PolicyNumber我都有5个NextPremiumDates

I want to display the 1st NextPremiumDate which is easy ...but i want to show the next NextPremiumDate only after the last NextPremiumDate has passed...How do i check if the last date has passed?? 我想显示第一个NextPremiumDate很容易...但是我想仅在最后一个NextPremiumDate通过之后才显示下一个NextPremiumDate ...如何检查最后一个日期是否过去了?

I mean if i have 5 dates in the table given above...how do i check if the 1st date has passed then show 2nd date ...if 2nd has passed show 3rd and so on. 我的意思是如果我在上表中有5个日期...我该如何检查第一个日期是否已过然后显示第二个日期...如果第二个日期已过显示第三个,依此类推。

SELECT Top 1 NextPremiumDate 
FROM MyTable
where NextPremiumDate >= getdate() 
ORDER BY NextPremiumDate ASC

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

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