Groups | Blog | Home
all groups > sql server (microsoft) > april 2007 >

sql server (microsoft) : extracting date from datetime execution performance time problem


Manikandan
4/26/2007 12:06:06 PM
Hi,
I need to take date value from datetime column.
I'm using convert function as below
convert(varchar,date,103)
I have a feeling that convert function taking much time to execute.
How about using cast function.
I'm querying a large number of records in table
I need a function for displaying date from datetime with minmimum
execution time
Kindly help me out

Thanks & Regards,
Mani
sienko
4/27/2007 12:36:36 AM
[quoted text, click to view]

If your issue is to have the query return dates in the 103 format (dd-
MM-yyyy) then I think convert is unavoidable. If you want to use the
results in an application that offers formatting (an ASP/ASP.Net
website) or VB/C#.Net then it would be better to just select the date
as is then you let the application handle the formatting.

The only way I can think you would want to handle the formatting or
extraction of the date alone in SQL Server would be perhaps to do
comparisons? You probably store the column as datetime and in a query
you want to retrieve records for a particular date regardless of time.
This can be handled by using...WHERE cast(date_col as
int)=cast(date_param as int).

All in all, I don't think the overhead of doing it your way is that
significant even for millions of records.
AddThis Social Bookmark Button