Groups | Blog | Home
all groups > sql server data mining > november 2003 >

sql server data mining : Formating Decmial Places in an Expression


Anthony Boyd
11/24/2003 6:33:07 PM
I'm trying to find a way to set the decimal places returned in an expression
through a view, I've listed the SQL statement below. The two expressions I
am looking at are the PagesHr and the BatchesHr, they are showing 12 decimal
places and I would like the to show only 2. I've used the LEFT and the
CONVERT commands but can not get the syntax correct.

SELECT strName, wrkDate, hoursworked, batches, pages, [timestamp], pages
/ hoursworked AS Pageshr, batches / hoursworked AS BatchesHr, username
FROM dbo.indexer

Thanks in advance

Allan Mitchell
11/25/2003 7:34:09 AM
Have you looked at

declare @a int, @b decimal(9,2)
set @a = 9
set @b = 10.2
select
@a/@b as [The Long Version],
CAST(@a/@b as decimal(10,2)) as [Short Version as Decimal],
STR(@a/@b,8,2) as [Short Version String]

--

----------------------------
Allan Mitchell (Microsoft SQL Server MVP)
MCSE,MCDBA
www.SQLDTS.com
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org



[quoted text, click to view]

Bernhard Saemmer
1/21/2004 11:21:29 AM

"Anthony Boyd" <boyd0029@mc.duke.edu> schrieb im Newsbeitrag
news:#GUjQLusDHA.2440@TK2MSFTNGP12.phx.gbl...
[quoted text, click to view]

Simply:

SELECT strName, wrkDate, hoursworked, batches, pages, [timestamp],
pages
/ hoursworked AS Pageshr, ROUND(batches / hoursworked, 2) AS BatchesHr,
username
FROM dbo.indexer


This worked for me as a customer wanted a measure with 3 decimals:

SELECT ROUND (x/y, z) as ROWNAME FROM.....

z = decimal places


greets

Bernhard

AddThis Social Bookmark Button