Stored procedure

D

Dib

Hi,

I am having a problem with this can some advice me please.

Insert Into #InvcInfo (CustId, RecType, InvcNum, InvcNum1, CheckNum, Charges

, Credits, AmountDue, TransDate, Status, BalDue)

SELECT i.CustId, i.RecType, i.InvcNum,Right(i.InvcNum,9) AS InvcNum1,
i.CheckNum

, Case When i.RecType = 1 Then Amt Else 0 End AS Charges

, Case When i.RecType < 1 Then Amt Else 0 End AS Credits

, Sign(i.RecType) * Amt AS AmountDue

,Case i.Charges - i.Credits AS BalDue -- This is where my problem is I
am creating a field

, i.TransDate, i.Status

FROM dbo.tblArOpenInvoice i (nolock)

WHERE i.CustId Between @CustIDFrom And @CustIDThru

AND i.TransDate <= @CutoffDate AND i.RecType=-2
 
R

Ron Hinds

The Case statement on the line that is failing is incomplete. What exactly
are you trying to test the case of? Or is the use of Case a mistake on that
line? When I remove Case from that line, the parser in Query Analyzer
doesn't give me an error:

Insert Into #InvcInfo (CustId, RecType, InvcNum, InvcNum1, CheckNum, Charges

, Credits, AmountDue, TransDate, Status, BalDue)

SELECT i.CustId, i.RecType, i.InvcNum,Right(i.InvcNum,9) AS InvcNum1,
i.CheckNum

, Case When i.RecType = 1 Then Amt Else 0 End AS Charges

, Case When i.RecType < 1 Then Amt Else 0 End AS Credits

, Sign(i.RecType) * Amt AS AmountDue

, i.Charges - i.Credits AS BalDue -- This is where my problem is I am
creating a field

, i.TransDate, i.Status

FROM dbo.tblArOpenInvoice i (nolock)

WHERE i.CustId Between @CustIDFrom And @CustIDThru

AND i.TransDate <= @CutoffDate AND i.RecType=-2
 
Top