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.
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.
Answer from Matthew Farwell on Stack OverflowCONVERT 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.
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.
CONVERT has a style parameter for date to string conversions.
https://learn.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql
I am trying to understand the difference between cast and convert.
I have googled it, and looked for explanations online and there are LOTS of them and I think this might just be a me thing, but for me, when I am learning something new I find it helpful when it is explained in a way that is simple and with minimal jargon (which I know is kind of hard because none of you really know where I am at in my SQL learning journey). So I thought I would just post here to ask a noob question lol 😛
Videos
CAST and CONVERT have similar functionality. CONVERT is specific to SQL Server, and allows for a greater breadth of flexibility when converting between date and time values, fractional numbers, and monetary signifiers. CAST is the more ANSI-standard of the two functions. Check this blog for examples of using both of those: http://sqltutorials.blogspot.com/2007/06/sql-cast-and-convert.html
The convert function can do more complex conversions, for example converting a datetime value into varchar using a specific format:
convert(varchar(16), dateTimeValue, 120)
No, performance is not a issue.(As far as your question describes both can be used and there is no difference between them but as martin said statement using CAST will cast to varchar(30) as it is it's default length)
CAST is an ANSI SQL-92
CONVERT is specific to SQL Server
CONVERT is specific to SQL Server, and allows for a greater breadth of flexibility when converting between date and time values, fractional numbers, and monetary signifiers.
Try this
SELECT DISTINCT CONVERT(VARCHAR(MAX), GETDATE(),108)
--and the other is saying to use
select distinct cast(GETDATE() as VARCHAR(MAX))
Performance wise, no difference. Just that CAST is ANSI-SQL(complying to the standards) so the query will be portable between server technologies.
Convert is specific to sql server but provides a richer set of options to convert.
Suggest using cast for portability unless you have to do otherwise.
King Regards, Sumit