By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,868 Members | 1,765 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,868 IT Pros & Developers. It's quick & easy.

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

P: 1
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(price 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
Expand|Select|Wrap|Line Numbers
  1. select title_id, cast (price as decimal(10,4)), cast(advance as decimal (10,4)) as'advance'
  2. from titles
  3. order by title_id asc
  4. compute avg (cast (price as decimal(10,4)))
  5. compute sum (cast(advance as decimal (10,4)))
Jan 26 '11 #1
Share this Question
Share on Google+
2 Replies


Rabbit
Expert Mod 10K+
P: 12,430
Cast the average, not the price.
Jan 26 '11 #2

ck9663
Expert 2.5K+
P: 2,878
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
Jan 26 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.