Conversion failed in sql
-
Hi All, I am getting conversion error when i try to execute the following query... please help i need this scenario to be fixed for another business logic
Conversion failed when converting the varchar value '12r' to data type int.
declare @t table
(
val varchar(10)
)
insert into @t
select '1' union
select '2' union
select '3' union
select '4' union
select 'et' union
select '4' union
select '6' union
select '7' union
select '8' union
select '9' union
select '12r'select * from @t where cast(val as int) > 3
-
Hi All, I am getting conversion error when i try to execute the following query... please help i need this scenario to be fixed for another business logic
Conversion failed when converting the varchar value '12r' to data type int.
declare @t table
(
val varchar(10)
)
insert into @t
select '1' union
select '2' union
select '3' union
select '4' union
select 'et' union
select '4' union
select '6' union
select '7' union
select '8' union
select '9' union
select '12r'select * from @t where cast(val as int) > 3
-
Hi All, I am getting conversion error when i try to execute the following query... please help i need this scenario to be fixed for another business logic
Conversion failed when converting the varchar value '12r' to data type int.
declare @t table
(
val varchar(10)
)
insert into @t
select '1' union
select '2' union
select '3' union
select '4' union
select 'et' union
select '4' union
select '6' union
select '7' union
select '8' union
select '9' union
select '12r'select * from @t where cast(val as int) > 3
Try this:
select *
from @t
where
cast((case when isnumeric(val) = 1 then val else 0 end) as int) > 3Edit -this will turn the 12r into a zero as it is not a valid integer.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
-
Hi All, I am getting conversion error when i try to execute the following query... please help i need this scenario to be fixed for another business logic
Conversion failed when converting the varchar value '12r' to data type int.
declare @t table
(
val varchar(10)
)
insert into @t
select '1' union
select '2' union
select '3' union
select '4' union
select 'et' union
select '4' union
select '6' union
select '7' union
select '8' union
select '9' union
select '12r'select * from @t where cast(val as int) > 3
This question really does ask for a disparaging response. If you can't work out that declaring a field of type int and trying to stuff text into it is going to fail and then cannot understand the very clear error message you should stop now and get an education.
Never underestimate the power of human stupidity RAH
-
Hi All, I am getting conversion error when i try to execute the following query... please help i need this scenario to be fixed for another business logic
Conversion failed when converting the varchar value '12r' to data type int.
declare @t table
(
val varchar(10)
)
insert into @t
select '1' union
select '2' union
select '3' union
select '4' union
select 'et' union
select '4' union
select '6' union
select '7' union
select '8' union
select '9' union
select '12r'select * from @t where cast(val as int) > 3
Perhaps JavaScript could cast '12r' into an int with a value of 12, but many other programming/scripting languages won't do so.
-
Perhaps JavaScript could cast '12r' into an int with a value of 12, but many other programming/scripting languages won't do so.
Bernhard Hiller wrote:
JavaScript could cast '12r' into an int
It does, how extraordinary, no wonder I loathe the script language. There is certain crappy banking software that will allow the traders to enter 12.65m or 328k as a trade values, WTF!
Never underestimate the power of human stupidity RAH
-
Bernhard Hiller wrote:
JavaScript could cast '12r' into an int
It does, how extraordinary, no wonder I loathe the script language. There is certain crappy banking software that will allow the traders to enter 12.65m or 328k as a trade values, WTF!
Never underestimate the power of human stupidity RAH
Mycroft Holmes wrote:
There is certain crappy banking software that will allow the traders to enter 12.65m or 328k as a trade values, WTF!
Considering how close K and M are on a qwerty keyboard :omg:
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
-
Bernhard Hiller wrote:
JavaScript could cast '12r' into an int
It does, how extraordinary, no wonder I loathe the script language. There is certain crappy banking software that will allow the traders to enter 12.65m or 328k as a trade values, WTF!
Never underestimate the power of human stupidity RAH
Mycroft, I see original poster did not respond, but really curious - what does J-script convert '12r' to???
-
Mycroft, I see original poster did not respond, but really curious - what does J-script convert '12r' to???
Richard.Berry100 wrote:
what does J-script convert '12r' to???
Dammed if I know, as a Silverlight dev I don't have to get my hands grubby by rabbiting around in script languages. The r probably stands for a currency sign, I image the conversion just drops the non numeric characters and turn the rest to an integer.
Never underestimate the power of human stupidity RAH