Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 9th, 2003, 12:40 PM
Registered User
 
Join Date: Jun 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Limiting of Calc. Field Output to 2 decimals

Is there a way to limit the output of a calculated field ( say it takes 40 and divide by 3) to decimals using SQL (I think one would use the CAST function, but I can not find the syntax for the decimal places)?

Thanks much in advance!

Vince
 
Old June 9th, 2003, 01:21 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

You specify a DECIMAL datatype as DECIMAL(precision,scale), where 'precision' is the number of significant digits in the result, and 'scale' in the number of decimal places to the right of the decimal point. Thus:

CAST(40.0/3.0 AS DECIMAL(8,2))

Note the use of decimal constants in the expression; if this was written as 40/3 you'd get 13.00 as '40' and '3' are integers and the expression would be treated as an integer expression. Adding the decimal point forces them to be treated as decimal data type.

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Output existing value to new field Neal SQL Server 2000 5 March 12th, 2007 09:51 AM
Output to Excel with selected field beagle Access VBA 1 November 2nd, 2006 09:43 AM
urgent doubt to run calc.exe from asp.net page geetha ASP.NET 1.0 and 1.1 Professional 0 July 19th, 2006 07:35 AM
Calc TEXTAREA ROWS & COLS based on Font Ron Howerton Classic ASP Basics 0 March 21st, 2005 11:17 AM
calc col from one table attached to another Jackie SQL Language 3 June 29th, 2003 02:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.