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 |
|
kdeutsch
Yak Posting Veteran
83 Posts |
Posted - 2009-11-17 : 14:26:13
|
| What happens is I need to check for zeros and do math if one does not exist or it its exists just make a zero, but it only works when both counts ar the same and never does the math if both are differentALTER Proc [dbo].[StrengthReport]ASdeclare @UnitId int,@MobId int,@UIC varchar(6),@UName varchar(60),@Req int,@Asgn int,@PAsgn int,@OverStruct int,@OSAsgn int, @POSAsgn int,@TAsgn int,@PTAsgn int, @State int,@NGB int,@AC int Declare Strength CURSOR FOR Select ud.intUnitMobId,ud.intMobilizationId,ud.strUic,o.orgstrUNameFrom tblUnitDeployData as ud LEFT OUTER JOIN cms.dbo.tblOrganization as o on o.orgstrUPC = ud.strUIC Order by intUnitMobId OPEN Strength FETCH NEXT FROM Strength INTO @UnitiD,@MobId,@UIC,@UName while @@FETCH_STATUS = 0 begin --Find all the report Data and assign to variables --Count the required strength Select @Req = Sum(intReqstr) from tblUnitPosition where intUnitMobId = @UnitId AND Substring(strpara, 1, 1) NOT IN ('9') --Get the Asgned strength of a Unit Select @Asgn = Sum(intAsgnStr) From tblUnitPosition Where intUnitMobID = @UnitId AND Substring(strpara, 1, 1) NOT IN ('9') --Get the Percent ASGN IF @Asgn > 0 SET @PAsgn = @Asgn / @Req ELSE IF @Asgn = 0 SET @PAsgn = 0I can put all the begin and ends in but it still nevers does the math, but I can do the same thing in other parts of code such asSelect @OverStruct = ISNULL(Count(intReqStr), 0) from tblUnitPosition where intUnitMobID = @UnitId AND Substring(strpara, 1, 1) = 9 --Get the O/S ASGN Select @OSAsgn = ISNULL(SUM(intAsgnStr), 0) from tblUnitPosition where intUnitMobID = @UnitId AND Substring(strpara, 1, 1) = 9 --Get the Percentage of O/S Assigned If @OSAsgn > 0 SET @POSAsgn = (@OSAsgn / @OverStruct) * 100 ELSE IF @OSAsgn = 0 Set @POSAsgn = 0This above works just fine in another part of the same SP |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
kdeutsch
Yak Posting Veteran
83 Posts |
Posted - 2009-11-18 : 08:14:37
|
| The problem has been solved, my problem was in trying to do division calculations I ws using a intteger intstead of a float and it could not handle the calculations. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|
|
|