April 26, 2004 at 2:27 am
my topic is "Serious Problem"
pls reply my question if ur expert in casting and converting.
becoz of this problem, my stored procedure is stuck and i cannot move forward
<a href="http://www.websolsoftware.com"> For IT jobs click here</a>
*Sukhoi*[font="Arial Narrow"][/font]
April 27, 2004 at 7:56 pm
Please don't double, or in this case triple post!!!
See http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=8&messageid=112989
April 27, 2004 at 8:38 pm
Dear sukhoi,
--example 1
declare @EchVPoin as varchar(5)
declare @noofVisits as varchar(5)
set @noofVisits=2
set @EchVpoin = 1+@noofVisits
select @EchVpoin
--example 2
declare @EchVPoin as varchar(5)
declare @noofVisits as varchar(5)
set @noofVisits=2
set @EchVpoin = 1/@noofVisits
select @EchVpoin
--example 3
declare @EchVPoin as varchar(5)
declare @noofVisits as varchar(5)
set @noofVisits=2
set @EchVpoin = 1/@noofVisits
select @EchVpoin
--example 4
declare @EchVPoin as varchar(5)
declare @noofVisits as varchar(5)
set @noofVisits=2
set @EchVpoin = convert(decimal(3,2),(1.0/@noofVisits))
select @EchVpoin
---exmpale 5
declare @EchVPoin as varchar(5)
declare @noofVisits as varchar(5)
set @noofVisits=2
set @EchVpoin = convert(decimal(6,6),(1.0/@noofVisits))
select @EchVpoin
exeute the above examples I think all ur problems can be soved
when u say select 1.0/2 it will give u proper result. but if u asssign it to a varchar variable it is giving u airthmatic overflow why? Simple to when you donot specify scale then float data type gives you too long (.500000000)value that is not fit in varchar(5) if u change the declaration ot varchar(30) it will work properly.
whaen you say 1/2 it will give you only zero. Because the denominator and numerator boht are integers it will give only interger result. In airth matic operation result will be given in highest datatype of the operands. whan you say 1.0/2 as 1.0 is float greater than int it will give you float result.
I think this make clear. If I am wrong please write again.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply