all groups > sql server programming > august 2004 >
You're in the

sql server programming

group:

Format retrieve data



Format retrieve data Ryan Joseph So
8/1/2004 11:52:31 PM
sql server programming:
How can I format my retrieve data on SELECT statement if for example I
am retrieving a numeric data with 6 decimal places and I want the return
data to retrieve only decimal places that is not equal to zero for
example 123.043000 and i want my SELECT query just to return 123.043
Supressing any zeros values is there any way to do this in T-SQL? just
like the FORMAT command in VB.NET. Thanks.


*** Sent via Developersdex http://www.developersdex.com ***
Re: Format retrieve data stephen.ward NO[at]SPAM mps.co.uk
8/2/2004 8:03:30 AM
Look at the STR command in Books On Line .

Something like
SELECT STR(1234.5678, 10, 2)
will return
Re: Format retrieve data stephen.ward NO[at]SPAM mps.co.uk
8/2/2004 8:27:17 AM
Try STR

Re: Format retrieve data Uri Dimant
8/2/2004 10:04:55 AM
Ryan
Declare a decimal variable as (18,3)


[quoted text, click to view]

Re: Format retrieve data Ryan Joseph So
8/3/2004 7:00:26 PM
Hi,

Actually I was hoping that the result would be the same as the format
command in VB. Ex. FORMAT(123.43000,"####.####") if you run this in VB
it will return 123.43 suppressing all zeros, this is what I want to do
in T-SQL if possible that when I use select in numeric data I want to
format it to supress all zero's. Thanks.




*** Sent via Developersdex http://www.developersdex.com ***
Re: Format retrieve data Ryan Joseph So
8/3/2004 7:49:20 PM
Hi,

Actually I was hoping that the result would be the same as the format
command in VB. Ex. FORMAT(123.43000,"####.####") if you run this in VB
it will return 123.43 suppressing all zeros, this is what I want to do
in T-SQL if possible that when I use select in numeric data I want to
format it to supress all zero's. Not rounding it or giving it an exact
decimal place but just remove the trailing zeros after the numbers.
Thanks.


*** Sent via Developersdex http://www.developersdex.com ***
Re: Format retrieve data Steve Kass
8/3/2004 10:21:58 PM
There's no FORMAT function, but you can use the available string functions:

declare @d decimal(10,6)
set @d = -3309.030800

select
replace(rtrim(replace(@d,'0',space(1))),space(1),'0')


Steve Kass
Drew University

[quoted text, click to view]
AddThis Social Bookmark Button