Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Converting nvarcher to numeric
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00490968
Message ID:
00490993
Views:
9
>When I using CONVERT function to convert nvarchar to numeric, I getting error message "Error converting data type nvarchar to numeric".
>I read help, and figured out that it is because there is charachters inside nvarchar variable.
>But is it possible to convert the same variables without errors, but zeros instead? :)

You can use isnumeric() function to check if a string represents valid number before trying to convert it. See example below:
DECLARE @nstr nvarchar(100), @num numeric(10,2)
set @nstr = '12345.58'
SELECT @num = CASE WHEN ISNUMERIC(@nstr) = 1
		THEN CONVERT(numeric, @nstr)
		ELSE 0 END
--sb--
Previous
Reply
Map
View

Click here to load this message in the networking platform