Varchar to decimal Question

  • This may be question that has already been asked, but I can't find anything about it.

    I have a field, that is a numeric (19,0) field, and I need to add a decimal point 2 spaces to the left of the end (convert it to a decimal, with the last two digits being the cents). When I try to convert it to a decimal it yells at me that it can't convert from numeric to numeric.

    So far I have only been able to either have the numbers converted to whole numbers, and have '.00' added to the end, but what I really want is for, for instance 999 to show up as 9.99, and 1234 to show up as 12.34., with no dollar sign.

    I've tried converting it to a char string and a varchar, and forcing a decimal point as a character, but I can't seem to get it justified to the right, and to leave leading spaces.

    This should NOT as difficult as it's being. Maybe I've been at this too long today.

  • this doesn't work?

    declare @d numeric(19, 0 )

           ,@d2 numeric(19,2)

    select @d = 999

    select @d2 = @d/100.00

    select @d2, @d

  • It worked with some modification.

    Since I had a complete TABLE of values for PRICE (or @d), I had to define it in a table as numeric(18,2)(sorry, my eyesight is going, and I thought I saw a 19, but it actually was an 18) populate the table and do a calculated expression of (PRICE/100.00) as PRICE1 in the select statement. It finally produced the stuff I was looking for.

    Thanks!

    (I'm calling it quits now. 12 hours straight of this is enough!)

  • Look for Data Type Precedence in BOL & that will help you.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply