Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Converting nvarcher to numeric
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00490968
Message ID:
00490993
Vues:
8
>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--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform