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.
| 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 isSelect Cast(Cast(Cast(((#TestUnion1.Quantity - #TestUnion2.Quantity)/#TestUnion2.Quantity) as Numeric(10,2))*100 AS numeric(10,2))AS varchar) + '%' As QuantityPercentwhich 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 LarssonHelsingborg, Sweden |
 |
|
|
tighers
Starting Member
2 Posts |
Posted - 2007-02-15 : 10:29:29
|
| Thanks very much Peter, a lot tidier solution. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-02-15 : 10:57:42
|
| Thank you.Peter LarssonHelsingborg, Sweden |
 |
|
|
|
|
|