Saturday 4 February 2017

MSSQL - Fix Error - Conversion failed when converting the varchar value 'cannot devide by 0' to data type int.


Conversion failed when converting the varchar value 'cannot devide by 0' to data type int.

Watch solution on YouTube

To Fix it Replace
Declare @x As Integer = 1
Declare @y As Integer = 0
Select Case When @y != 0 Then @x/@y Else 'cannot devide by 0' end

With

Declare @x As Integer = 1
Declare @y As Integer = 0
Select Case When @y != 0 Then Convert(Varchar, @x/@y) Else 'cannot devide by 0' end

No comments:

Post a Comment