Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2003
    Location
    NJ USA
    Posts
    19

    Unanswered: Convert real to Varchar.

    Hello All,

    I am facing problem to get exacltly value using convert function. Please follow below steps.

    Crete table A (ID Real)

    Insert into A values(0.0013)

    select convert(varchar, convert(DECIMAL(30,6), id)) from A

    ----------------
    0.001300

    I am getting '0.001300' values because scale is 6 in Decimal so that is why I am getting but want to get '0.0013' values. Please let me know
    M. Jain

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    HEY NJ!

    isn't it "Jersey"?

    Doesn't this work?

    Code:
    USE Northwind
    GO
    
    CREATE TABLE A ([ID] Real)
    GO
    
    INSERT INTO A ([ID]) values(0.0013)
    
    SELECT CONVERT(varchar(45), [ID]) FROM A
    GO
    DROP TABLE A
    GO
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  3. #3
    Join Date
    Nov 2003
    Location
    NJ USA
    Posts
    19

    Convert real to Varchar.

    Hello All,

    I am facing problem to get exacltly value using convert function. Please follow below steps.

    Crete table A (ID Real)

    Insert into A values(0.000013)

    select * from a

    Ouput
    -------------------
    1.13 e05

    But I want '0.000013' to display so that is why I have written below Query.

    select convert(varchar, convert(DECIMAL(30,6), id)) from A

    ----------------
    0.00001300

    I am getting '0.001300' values because scale is 6 in Decimal so that is why I am getting but want to get '0.0013' values. Please let me know

    ---- Is any function using that I can remove added/padded zero suffix.

    Current Expected result.
    0.00001300 to 0.000013
    M. Jain

  4. #4
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Did you try what I gave you?
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  5. #5
    Join Date
    Feb 2002
    Posts
    2,232
    You use 2 different numbers:

    0.0013 and 0.000013 - which one is it ?

    If it is the first then just change the decimal from 6 to 4.

  6. #6
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Does the precision matter if you're going to varchar?

    And I still want to know

    What exit?
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •