Solved

simple sql qustion (formating outputs?)

Posted on 2001-09-13
7
184 Views
Last Modified: 2010-04-06


how to format output from sql statment?

for example i have:

select a, b, a/b
from table1

and for a/b i got results with too many decimals and i don;t need it.
how to format(with 2 decimals) output?

thanks.
0
Comment
Question by:zastava101
7 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 55 total points
ID: 6480344
you could use something like this

query1.sql.text := 'select a, b, a/b f1 from table'; //a/b is aliased to f1
query1.open;
Tfloatfield(query1.fieldbyname('f1')).displaymask := '#0.00';

(not tested)

instead of do it in runtime, you can do it in design-time,
by creating persistant fields, and then just adjust the property displaymask of this field

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6480349
appendix,

depending on your database, you can do the formatting within your sql-statement
0
 
LVL 10

Expert Comment

by:Jacco
ID: 6480712
For MSSQL:

select
  a,
  b,
  convert(numeric(9,2), a/b) as f1

For Interbase

select
  a,
  b,
  cast((a/b) as numeric(9,2)) as f1

Regards Jacco
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 27

Expert Comment

by:kretzschmar
ID: 6480875
for oracle

select
a,
b,
to_number(to_char(a/b,'FM9999999990D00')) as f1

;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6480877
or, also oracle

select
a,
b,
trunc((a/b)*100)/100  f1

meikl ;-)
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 6481427
for MySQL:

SELECT round(a, 3)
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6872461
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if still open in seven days.  Please post closing recommendations before that time.

Question(s) below appears to have been abandoned. Your options are:
 
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you. You must tell the participants why you wish to do this, and allow for Expert response.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question. Again, please comment to advise the other participants why you wish to do this.

For special handling needs, please post a zero point question in the link below and include the question QID/link(s) that it regards.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click the Help Desk link on the left for Member Guidelines, Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Please click you Member Profile to view your question history and keep them all current with updates as the collaboration effort continues, to track all your open and locked questions at this site.  If you are an EE Pro user, use the Power Search option to find them.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20001252.html
http://www.experts-exchange.com/questions/Q.20026086.html
http://www.experts-exchange.com/questions/Q.20066091.html
http://www.experts-exchange.com/questions/Q.20070791.html
http://www.experts-exchange.com/questions/Q.20070795.html
http://www.experts-exchange.com/questions/Q.20081086.html
http://www.experts-exchange.com/questions/Q.20081708.html
http://www.experts-exchange.com/questions/Q.20082186.html
http://www.experts-exchange.com/questions/Q.20087813.html
http://www.experts-exchange.com/questions/Q.20094507.html
http://www.experts-exchange.com/questions/Q.20103740.html
http://www.experts-exchange.com/questions/Q.20104227.html
http://www.experts-exchange.com/questions/Q.20108539.html
http://www.experts-exchange.com/questions/Q.20112131.html
http://www.experts-exchange.com/questions/Q.20118798.html
http://www.experts-exchange.com/questions/Q.20141336.html
http://www.experts-exchange.com/questions/Q.20157666.html
http://www.experts-exchange.com/questions/Q.20159442.html
http://www.experts-exchange.com/questions/Q.20177987.html
http://www.experts-exchange.com/questions/Q.20182504.html
http://www.experts-exchange.com/questions/Q.20193634.html
http://www.experts-exchange.com/questions/Q.20194167.html
http://www.experts-exchange.com/questions/Q.20090036.html
http://www.experts-exchange.com/questions/Q.20265702.html


To view your locked questions, please click the following link(s) and evaluate the proposed answer.
http://www.experts-exchange.com/questions/Q.20002824.html
http://www.experts-exchange.com/questions/Q.20179302.html
http://www.experts-exchange.com/questions/Q.20182632.html

PLEASE DO NOT AWARD THE POINTS TO ME.  
 
------------>  EXPERTS:  Please leave any comments regarding your closing recommendations if this item remains inactive another seven (7) days.  Also, if you are interested in the cleanup effort, please click this link http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643
 
Thank you everyone.
 
Moondancer
Moderator @ Experts Exchange

P.S.  For any year 2000 questions, special attention is needed to ensure the first correct response is awarded, since they are not in the comment date order, but rather in Member ID order.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now