I have a table (mytable
) that contains:
id, date
and some rows (the Id is for the example):
4235 null
3563 2013-11-27 08:02:53.917
3143 2013-11-27 01:04:51.917
1455 null
5223 2013-11-26 08:02:53.917
2123 2013-11-25 08:02:53.917
I want to select all the rows that their date before today or the date is null.
so in my example, if I run the query on 2013-11-27
I want to get:
4235 null
1455 null
5223 2013-11-26 08:02:53.917
2123 2013-11-25 08:02:53.917
I think to do it with:
select case when
(
(select DATEPART(yyyy,dailybudgetexceeded) from sensplit_commercial_goal where
commercialGoalId = 'dbe20d71-e304-4989-8524-5feef61d32a7') >= YEAR(GETDATE())
or...
but maybe there is a shorter way.
any help appreciated!
To get the current date and time in SQL Server, use the GETDATE() function. This function returns a datetime data type; in other words, it contains both the date and the time, e.g. 2019-08-20 10:22:34 .
select * from mytable
where [date] < Convert(date, getdate()) or [date] is null
SQLFiddle Demo
select *
from sensplit_commercial_goal
where commercialGoalId = 'dbe20d71-e304-4989-8524-5feef61d32a7'
and (dailybudgetexceeded < getdate() or dailybudgetexceeded is null)
SELECT *
FROM sensplit_commercial_goal
WHERE dailybudgetexceeded < CONVERT(date, GETDATE()) OR dailybudgetexceeded IS NULL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With