开发者

How to query on a column of datatype long storing datetime values?

开发者 https://www.devze.com 2023-01-15 04:26 出处:网络
I am working on a table which has a column called ccDate of type long which stores the date values in long format- for example 20021218. Actually it is a datetime value for 2002-12-18 (yyyy-MM-DD). No

I am working on a table which has a column called ccDate of type long which stores the date values in long format - for example 20021218. Actually it is a datetime value for 2002-12-18 (yyyy-MM-DD). Now i want to query records from this table comparing this datetime values. for example get all records where ccDate < todays's date. How can i do this ? (note : i am working on SQLServer). I am looking for a datab开发者_C百科ase function which can automatically convert these long values to date & compare while querying.


Well assuming that your actual datatype in SQL Server is an integer then something like this will work:

select *
From myTable
Where Cast(Cast(ccDate as varchar(10)) as datetime) < getdate()
0

精彩评论

暂无评论...
验证码 换一张
取 消