Friday 10 November 2017

Error converting varchar to numeric in Sql Server.

In this article, We will discuss Why "Error converting varchar to numeric in sql" and How to resolve this error.

While we are working on any project or development work there is a need to retrieve data from one column but whose datatype is varchar but we need to show the output in decimal format.

So we will implement like this,

select convert(decimal(18,3),BillRate) from BillDetails

or
select cast(BillRate as decimal(18,3)) from BillDetails

This Works absolutely fine but sometimes it will still create error like "Error converting varchar to numeric".

This issue arises because may be null or empty or character or string value present in that Column value and as we know null or empty or character or string can't convert into decimal.

To fix this error we need to skip these values by applying filter condition like in where clause.

0 comments:

Post a Comment