pls reply to my problem

  • 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]

  • It would help if your subject heading gave a clue as to what your problem is.  "Serious Problem" could be anything from a coding error to a flat tire!

    How about a heading "Problem with CAST and CONVERT"?

    Dana

    Connecticut, USA



    Dana
    Connecticut, USA
    Dana

  • Please don't double, or in this case triple post!!!

    See http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=8&messageid=112989

  •  

    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