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 database function which can automatically convert these long values to date & compare while querying.
+1
A:
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()
Barry
2010-09-09 07:10:50
Thanks a lot. It works!!!
Siddharth
2010-09-09 09:52:37