all groups > sql server new users > july 2006 >
You're in the

sql server new users

group:

Howto remove decimals in a numeric field


Howto remove decimals in a numeric field Ana_T
7/28/2006 12:00:00 AM
sql server new users:
Hi,

I use a numeric field (vs. nvarchar) to log the KM of a vehicle because I'd
like the data to be displayed with the 1000 separator (123.456). In a web
page, the data is displayed with decimals (123.456,00). I removed the
decimal setting in the server's regional configuration with no avail. Is
there a place in SQL2K where regional settings are stored?

TIA

Ana

Re: Howto remove decimals in a numeric field Arnie Rowland
7/28/2006 8:21:18 AM
I believe that the presentation of numeric separators is controlled by the
Windows regional setting.

In the Control Panel, select Region and Language Settings, and make the
change there.

However, if it concerns you about making a change that would effect every
operation on the computer, perhaps casting the numeric fields to varchar in
the query that is used to retrieve the data for display will solve the
problem.

--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc

Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous


[quoted text, click to view]

Re: Howto remove decimals in a numeric field Arnie Rowland
7/28/2006 9:46:11 AM
You don't 'add' numeric separators in a cast (or in a query for that =
matter.) I understood that the only separator you desired was the =
period.

You MUST change the Regional Settings on the WEB Servers to a numeric =
format that is consistent with the presentation you desire. If the =
Regional settings on the WEB Server is set to display a comma instead of =
a period as the decimal separator, that is what you will display.

Now if you cannot change the Regional settings on the Web server, you =
may try the following. (I'm going to use a 'unusual' example so that you =
will get the idea of how this technique may help you.) Run this code in =
Query Analyzer to see the difference.

DECLARE @MyTable table
( RowID int IDENTITY
, Mileage numeric(18,3)
)

SET NOCOUNT ON

INSERT INTO @MyTable VALUES ( 125.5 )
INSERT INTO @MyTable VALUES ( 69.345 )
INSERT INTO @MyTable VALUES ( 123456.789 )
INSERT INTO @MyTable VALUES ( 2000.500 )
INSERT INTO @MyTable VALUES ( 1111.1 )
INSERT INTO @MyTable VALUES ( 100.0 )
=20
--Numeric display
SELECT=20
RowID
, Mileage
FROM @MyTable
=20
-- Altered display. Replace the period with another character(s)
SELECT=20
RowID
, Mileage =3D replace( cast( Mileage as varchar(20) ), '.', '[~]' )
FROM @MyTable

Using cast() would allow you to move the decimal value into a text form =
that would not be changed by the application's use of the regional =
settings. Of course, on the application side, you need to handle the =
value as a string -not as a number. Replace() is used after (on the =
outside of ) the conversion to change the period into a different =
character.

--=20
Arnie Rowland, Ph.D.
Westwood Consulting, Inc

Most good judgment comes from experience.=20
Most experience comes from bad judgment.=20
- Anonymous


[quoted text, click to view]
Re: Howto remove decimals in a numeric field Ana_T
7/28/2006 6:04:30 PM
Thank you Arnie.
I tried CAST(numeric_field AS varchar) and I think I'm missing something.
How do I add the numeric separators in a query?
TIA

"Arnie Rowland" <arnie at 1568 . moc> escribió en el mensaje
news:%23YRs6llsGHA.372@TK2MSFTNGP06.phx.gbl...
[quoted text, click to view]

AddThis Social Bookmark Button