What is the general guidance on when you should use CAST versus CONVERT? Is there any performance issues related to choosing one versus the other? Is one closer to ANSI-SQL?
Is ANSI-SQL preferable? If so, why?
lush
2009-04-01 21:23:21
ANSI-SQL is more portable across database platforms. So if you ever wanted to use the query on Orcale, DB2, etc. The ANSI version is more likely to work without changes.
JohnFx
2009-04-01 21:33:42
+18
A:
CONVERT is SQL Server specific, CAST is ANSI.
CONVERT is more flexible in that you can format dates etc. Other than that, they are pretty much the same. If you don't care about the extended features, use CAST.
MatthieuF
2009-04-01 21:39:02