How to convert datatype from nvarchar to numeric

48 Views Asked by At

enter image description here

I can not convert datatype from nvarchar and null to decimal

enter image description here I met the error. How can I resolve it. I think I should remove null after casting the datatype. Please help me, I just a beginner to practice SQL.

1

There are 1 best solutions below

2
Yoji On

in SQL to convert from nvarchar to numeric you can use 2 different methods. The first is CAST():

SELECT CAST('123.45' AS NUMERIC(10,2)) AS ConvertedValue;

And the expression to use it correctly is this: CAST(expression AS datatype(length))

The second is CONVERT():

SELECT CONVERT(NUMERIC(10,2), '123.45') AS ConvertedValue;

And the expression is this: CONVERT(data_type(length), expression, style)