With SQL Server, you can convert one type to another, for example an INT to VARCHAR using either the CAST or CONVERT function.
Here are both options in action:
Using CAST
|
|
Using CONVERT
|
|
Key points
Always specify the length for VARCHAR (e.g., VARCHAR(10)), otherwise SQL Server uses a default length of 30.
If you omit the length, it might cause truncation or unexpected results in some contexts.
Documentation
Reference: Microsoft Learn.
Follow me
Thanks for reading this article. Make sure to follow me on X, subscribe to my Substack publication and bookmark my blog to read more in the future.
Credits: Image from Microsoft Server