How to convert data type from varchar to number in SQL Server? 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?
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:

alter view dbo.myView as 
  select
    ....
    , store_nbr = try_cast(dbo.customer.store_nbr as int)
    ....