Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Number Formatting

Author  Topic 

tighers
Starting Member

2 Posts

Posted - 2007-02-15 : 09:43:32
Using a stored procedure in SQL Server 2005 to among other things calculate percentage between two date ranges. Using temporay table and then select statement. I have two int columns (in 2 different temporay tables) with a quantity value e.g. 11 and 14. The sql statement I'm using to get percent difference between the two values is

Select Cast(Cast(Cast(((#TestUnion1.Quantity - #TestUnion2.Quantity)/#TestUnion2.Quantity) as Numeric(10,2))*100 AS numeric(10,2))AS varchar) + '%' As QuantityPercent

which should give me -21.42% but instead is giving 0.00%. Any ideas on where I'm going wrong? Thanks, T

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-15 : 09:52:21
SELECT LTRIM(STR(100.0 * (#TestUnion1.Quantity - #TestUnion2.Quantity) / #TestUnion2.Quantity, 10, 2)) + '%'


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

tighers
Starting Member

2 Posts

Posted - 2007-02-15 : 10:29:29
Thanks very much Peter, a lot tidier solution.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-15 : 10:57:42
Thank you.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -