I want to convert a field currently in varchar data type to number data type in the Views of SQL Server say (dbo.CUSTOMER.STORE_NBR)
from Varchar to number.
How to do that ?
Will CONVERT
function will do the necessity?
If yes, can you help us with syntax?
Sql-server – How to convert data type from varchar to number in SQL Server
sql server
Related Question
- Sql-server – How to convert varchar iPv4 Address into a number deterministically
- Sql-server – SSIS changes SQL Server source data type from date to WSTR
- SQL Server Conversion Error – Fixing Varchar to Int Conversion Failure
- SQL Server – How to Sum a Varchar Data Type
- Sql-server – Convert Varchar To Datetime and Add Seconds
Best Answer
In Sql Server 2012 and up: each of these will return
null
when the conversion fails instead of an error.try_convert(datatype,val)
try_cast(val as datatype)
try_parse(val as datatype [using culture])
So if you want to change the way a view is returning the value you would use something like: