I have a number: 3320.8000000. My expected result is 3320.80 based on a
dynamic decimal parameter for example:
declare idecimal int
select @.idecimal=3
convert(decimal(20,@.idecimal),number) does not work - error message.
How can I accomplish this?Format the value client side. Why would you want to do this in the database?
David Portas
SQL Server MVP
--|||I have a stored that procedure generates data for a report. The data is
stored in the database as decimal (20,7). Are you saying there is no easy wa
y
to do this using T-SQL?
"David Portas" wrote:
> Format the value client side. Why would you want to do this in the databas
e?
> --
> David Portas
> SQL Server MVP
> --
>
>|||Boy, you were one of the kids asleep in the back of my 20+ years of
database classes!! Where do we do display in a tiered architecture
(this is faaaar more fundamental question than SQL)? The front end !!
Never,never in the database!!
SQL is a static data type language. THIS IS A FUNDAMENTAL PROGRAMMING
CONCEPT!! Why did you think you could change data types in a schema?
You so ignorant or stupid that you are dangerous to people.|||Ultimately the display format is controlled by the client application, not
by SQL Server. A query always has fixed metadata and that includes the
precision and scale of each column. I think your options therefore are to
use dynamic SQL or to cast the value as a string and return it that way. You
can use the STR function to output a string with a varying numberof
decimals:
SELECT STR(x,20,@.d)
FROM T1
However, this might cause you some problems if your reporting application
needs to do arithmetic on the results.
David Portas
SQL Server MVP
--
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment