473,382 Members | 1,717 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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(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
2 1938
Rabbit
12,516 Expert Mod 8TB
Cast the average, not the price.
Jan 26 '11 #2
ck9663
2,878 Expert 2GB
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

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

Similar topics

5
by: Aeon Twilight | last post by:
REFERENCE: http://us4.php.net/manual/en/function.include.php Example 16-7. include() through HTTP Example 16-10. include() and the return() statement -------------------- return.php...
6
by: Kevin Frey | last post by:
Hello, I have a table which contains some nullable columns. I want to write a single query, which can be prepared (ie. prepared statement), that can handle null or non-null values for the where...
16
by: Kevin Goodsell | last post by:
What do you think is the best way to handle a compiler warning about comparing an unsigned value to a signed value? Cast to silence it? Disable that warning altogether? Or just live with it? On...
5
by: pmud | last post by:
Hi, I am using a compare validator in asp.net application(c# code). This is used for comparing a value enterd by the user against the primary key in the SQL database. IF the VALUE ENTERED BY THE...
1
by: bonnie.tangyn | last post by:
Hello all Would it be possible to store javascript document.forms.value to ASP session as global variable? If it is not possible, how can I pass the javascript document.forms.value to...
4
by: Matt Kruse | last post by:
According to standards, if an option is selected and it has no VALUE attribute, the contents of the option tag is to be submitted. So: <select name="sel"> <option selected>Value</option>...
3
by: tariq103 | last post by:
How would i compute the mean value of a matrix from a txt. file? help
1
by: ScripterSam | last post by:
Hi friends, I have declared a variable in the script section in head of the html. Now I want that a text within the body have the value of that variable... Is it possible at all..? here is my code...
2
by: Nathan Pinno | last post by:
Hello all, Is it possible to return a variable and then use it like the following: dir exp_1: while hen != "*" sum = sum + hen return sum
4
by: sweatha | last post by:
Hi In sql server 2005 I have a column as GraduationYear Decimal(4,0). In asp.net I used the coding for that as SqlParameter GraduationYear = new SqlParameter("@GraduationYear",...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.