I regularly use such code as:
in order to convert a date within a database to a format more suitable for displaying.
But I've come across code that does such things within the WHERE clause and the JOIN clause. For example:
WHERE CAST(CONVERT(VARCHAR(11),Expiry_Date,106) AS DATETIME) >= CAST(CONVERT(VARCHAR(11),GETDATE(),106) AS DATETIME))
I've never bothered converting dates where they haven't been required as output fields for displaying or suchlike.
My first thought is that this code is unnecessary and will just slow things down.
Am I correct in believing this, or is there a good reason for using such code where the date will never be selected for output?
Steve HallLinkedinBlog Site