how to write query to get today's date data in SQL server
?
select * from tbl_name where date = <Todays_date>
how to write query to get today's date data in SQL server
?
select * from tbl_name where date = <Todays_date>
正しい答えは、あなたの正確なタイプによって異なりますdatecolumn
。それがタイプであると仮定しますDate
:
select * from tbl_name
where datecolumn = cast(getdate() as Date)
それがある場合DateTime
:
select * from tbl_name
where cast(datecolumn as Date) = cast(getdate() as Date)
Mitch Wheat's answer is not sargableのようですが、これが正しいかどうかはわかりません。
注意: DATEDIFF()
LHS の a (またはその他の計算) は Sargable ではありませんが、そのままCast(x to Date)
です。
SELECT *
FROM tbl_name
WHERE date >= cast(getdate() as date)
and date < cast(getdate()+1 as date)
select * from tbl_name where date = cast(getdate() as Date)
http://msdn.microsoft.com/en-us/library/ms187928.aspxおよびhttps://msdn.microsoft.com/en-IN/library/ms188383.aspxをCAST
参照してください。GETDATE()