Hello I'm trying to write a SQL Statement along the lines of...
SELECT stringField + ' : ' + STR(decimalField) AS myField FROM tablename WHERE myCondition = myValue
Where stringField is a String field and decimalField is a Decimal Field in my Table.
In this statement it converts the decimal field to a string value so that it doesn't throw a conversion error but unfortunatly it seems to round up the value to an integer value and cuts off all my decimal places.
How can I get it to keep the Decimal Places?STR(decimalField,6,2)|||Thanks Man appreciated one other question.
When I do a "SELECT decimalField FROM table" and ouput it to HTML it always outputs as 22.4500 or 132.220 etc. I could easilly remove the 0's on the right using the code behind my HTML but can I do this in SQL instead?
I'm guessing it's done in a similar way to the above solution?
Thanks for you help so far.|||SELECT CAST(decimalField AS INT) AS NonDecimalField FROM table|||declare @.i decimal(20,10)
set @.i = 132.2200
select @.i, ltrim(str(@.i, 10, 2))|||Thanks guys.
Sorry derrick - that removed all decimal places - all I wanted was to remove any preceding zeros.
rdjabarov - that worked fine thanks
No comments:
Post a Comment