Is it possible to cast the return value of a compute avg(X value) to show 4 decimal?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thierry savard
    New Member
    • Jan 2011
    • 1

    Is it possible to cast the return value of a compute avg(X value) to show 4 decimal?

    I want the 2 compute column to show only 4 decimal, but I cant find a way to affect the return value of 'em.

    I wrote down this command "compute avg(x)" because I need the average to be in a seperate table.

    When you use compute avg(x) here x is cast (price as decimal(10,4)) because I need the price to show up in the main table, and I need it with 4 decimals.

    So I need a way to cast the return value of compute avg(x) but I dunno how to write it down.

    I've tried these form and both doesnt work

    cast (compute avg(cast (price blabla)) blabla)
    compute cast(avg(cast(p rice blabla))blabla)

    I am not sure what you want me to group by or rollup and how it'll help me here, can you develop ?

    Heres my code
    Code:
    select title_id, cast (price as decimal(10,4)), cast(advance as decimal (10,4)) as'advance'
    from titles
    order by title_id asc
    compute avg (cast (price as decimal(10,4)))
    compute sum (cast(advance as decimal (10,4)))
    Last edited by Niheel; Jan 26 '11, 08:14 PM.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Cast the average, not the price.

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      Try to use GROUP BY instead. According to BOL


      Important

      This feature will be removed in the next version of Microsoft SQL Server. Do not use this feature in new development work, and modify applications that currently use this feature as soon as possible. Use ROLLUP instead. For more information, see GROUP BY (Transact-SQL).
      Happy Coding!!!

      ~~ CK

      Comment

      Working...