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?
What is the general guidance on when you should use CAST versus CONVERT ?
Share
CONVERTis SQL Server specific,CASTis ANSI.CONVERTis 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, useCAST.EDIT:
As noted by @beruic and @C-F in the comments below, there is possible loss of precision when an implicit conversion is used (that is one where you use neither CAST nor CONVERT). For further information, see CAST and CONVERT and in particular this graphic: SQL Server Data Type Conversion Chart. With this extra information, the original advice still remains the same. Use CAST where possible.