Re: Convert Fraction to Decimal Type

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



As you can see, I'm having to convert part of the prodName column which is a string to integer type. lengthVal is already an integer.

I think the suggestions by Aaron or Erland will work for you. All you need to do is specify a decimal literal instead of integer as one of the expressions. The lengthVal column and CONVERT expression can remain integer.

--
Hope this helps.

Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/

"Scott" <sbailey@xxxxxxxxxxxxxxx> wrote in message news:%23SwbMYJ3JHA.1092@xxxxxxxxxxxxxxxxxxxxxxx

I realize that works, but when I run the calculation with column variables inserted, it always returns 0.000000.

Below is my calculation with column values inserted:

((2*(CONVERT(INT, RIGHT(prodName, 1))))/12)* lengthVal

As you can see, I'm having to convert part of the prodName column which is a string to integer type. lengthVal is already an integer.

Any ideas?



"Dan Guzman" <guzmanda@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:Oc6hJRJ3JHA.5728@xxxxxxxxxxxxxxxxxxxxxxx
SELECT (CONVERT(decimal(10, 6),((2*4)/12)))

The issue here is that all of the expressions are integers so the result is also integer. Try:

SELECT (2*4)/12.0


--
Hope this helps.

Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/

"Scott" <sbailey@xxxxxxxxxxxxxxx> wrote in message news:u7jWzNJ3JHA.4272@xxxxxxxxxxxxxxxxxxxxxxx
I need to make a calculated value that translates to
((2*4)/12)



In my code below, I tried using CONVERTand I've even tried DECIMAL format, but I can never display the decimal values of the above formula. I've always used this method when dealing with percents and it worked. What data type must I use to display the formula to 6 digits?


CODE:

SELECT (CONVERT(decimal(10, 6),((2*4)/12)))










.



Relevant Pages

  • Re: error converting the varchar value True to a column of data smal
    ... > Is this indicating a problem with the varchar parameters or the smallint ... The string "True" can be coersed ... Afaik, there is no symbolic value TRUE in SQL, the Boolean concept exists, ... If you merely coerse to an integer type, ADO will whine about type mismatch. ...
    (microsoft.public.vb.database.ado)
  • Re: String or Numeric Variable?
    ... it appears that using numeric constants will solve the 'readability' ... Obviously the BYTE or INTEGER type would use less memory. ... >> Is it best to use a variable of type string and either have it equal ... > a few more nanoseconds to execute. ...
    (comp.lang.basic.visual.misc)
  • Re: how to change pid to string in linux gcc
    ... > Here is a small program which uses pid_t and converts it to a string and displays the string on the standard output. ... is (int or long etc.). ... if long is the largest integer type there is. ... long integer values (for 64-bit integers a length of 22 chars should be ...
    (comp.unix.programmer)
  • Re: strlcpy -- or lack thereof
    ... constant integer with a value of zero, eg sqrt, 'in the ... A so-called 'C string' is a sequence of bytes with values!= 0, ... 'does s point to the string terminator'. ... whose type, in my opinion, really shouldn't be an integer type' ...
    (comp.unix.programmer)
  • Re: What does the standard say about array access wraparound?
    ... why should a variable used as array index be of ... any integer type does the job: ... One of the expressions shall have type ``pointer to object type'', ... Dan Pop ...
    (comp.lang.c)