June 14, 2012

Explicit datetime values in SQL server queries

It is common to type some temporary queries by hand in SQL Server Management Studio. In order to filter results by date easy to read datetime format can be used:
select * from Posts where CreationDate > '12 Apr 2012 09:07'
Time part can be omitted as well:
select * from Posts where CreationDate > '12 Apr 2012'
This format should work in most scenarios since it is difficult for SQL parser to mess with such an obvious date format. Certainly I would not recommend using it in production code.

No comments:

Post a Comment