Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SP used to calculate two lines from same table

Status
Not open for further replies.

jamguy

Programmer
Jun 1, 2007
6
CA
I have a SP used to calculate a new record (LINE) based on the parameters passed for @PLN and @LN and @OPER(+ or -). The values are in the same table so I join the table to itself. The problem I have is when one of the lines passed does not exists it (obviously :)) doesn't do the calculation, is there a way I can pass a 0 value for the record that doesn't exist, so the calculation will caculate the one value + 0 amount? Here's my code

So the EXEC sql command would look something like sp_addLines 3,1,'+',2 (add lines 1 and 2 to become line 3)

Code:
SELECT	PERIOD, A.ORG_ENTRY_HANDLE,(@LN,5,0)
,
(ISNULL(A.ACTUAL_PRYR,0) '+ @OPER + ' ISNULL(B.ACTUAL_PRYR,0)) 
FROM T_FDW_CSMDM_CFL_DATA_ALL A, T_FDW_CSMDM_CFL_DATA_ALL B
	WHERE A.LINE_NUMBER = STR(@LN_A,5,0)
	AND   B.LINE_NUMBER = STR(@LN_B,5,0)
	AND   A.ORG_ENTRY = B.ORG_ENTRY
 
use a left join, then just do coalesce(column, 0)

--------------------
Procrastinate Now!
 
Will the left join work if the missing line is from Table B, i.e. the 1st line passed is missing?

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top