This SQL:
select FORMAT(lNum,'##-###-##-###')
from [rpt].[myView]
Produces the following error:
Argument data type varchar is invalid for argument 1 of format function.
lNum
is a varchar(10)
Running SQL Server 2012
Definition and Usage. The FORMAT() function formats a value with the specified format (and an optional culture in SQL Server 2017). Use the FORMAT() function to format date/time values and number values. For general data type conversions, use CAST() or CONVERT().
You can specify the format of the dates in your statements using CONVERT and FORMAT. For example: select convert(varchar(max), DateColumn, 13), format(DateColumn, 'dd-MMM-yyyy')
FORMAT returns NULL for errors other than a culture that is not valid. For example, NULL is returned if the value specified in format is not valid. The FORMAT function is nondeterministic.
varchar
isn't supported as the first argument to FORMAT
. The only categories of datatypes supported are Date and Time
and Numeric
.
You could do
select FORMAT(cast(lNum as numeric),'##-###-##-###') from [rpt].[myView]
From levelonehuman's comment : Documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With