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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why am i getting this syntax error?

Status
Not open for further replies.

Blitz

Technical User
Jul 7, 2000
171
US
I have this code in a stored proceedure, the error i get is "Error 156: Incorrect syntax near the keyword 'END'.". Its probably something simple as I dont yet have a firm grasp of SQL. Thanks for any help.

BEGIN

Select @returnval = 0


BEGIN TRANSACTION AddEditJournalEntry

IF (@blnjemodified = '1')
BEGIN
IF (@blnjenew ='1')
BEGIN
INSERT INTO acctunpjeJournalEntries (TransactionID,AssociationID,JEDate,JEAccrue,JEReverseDate,JEReference,JEEnteredDate,JEEnteredUserID)
VALUES (@TransactionID,@AssociationID,@JEDate,@JEAccrue,@JEReverseDate,@JEReference,GetDate(),@JEEnteredUserID
END
IF (@blnjenew ='1')
BEGIN
UPDATE acctunpjeJournalEntries SET TransactionID = @TransactionID,AssociationID = @Associationid,JEDate = @JeDate,JEAccrue = @JEAccrue,JEReverseDate = @JEReverseDate,JEReference = @JEReference,JEEnteredDate = GetDate(),JEEnteredUserID = @JeEnteredUserId
WHERE UnPJournalEntryID = @JournalEntryId
END
END





IF (@@ERROR <> 0) Goto OnErrorTrap


COMMIT TRANSACTION AddEditJournalEntry
goto OnExit
END

OnErrorTrap:

/* oops!!! we ran into a problem. Return the
SQL Server error code to ADO and rollback
the transaction */


select @returnval = @@Error
ROLLBACK TRANSACTION AddEditJournalEntry


OnExit:
RETURN @returnval

GO
 
remove your first BEGIN right before the Select @returnval = 0
line.

Thanks

J. Kusch
 
Blitz, in the future, to undestand the problem when you have lots of begin end statements, you should count up the number of begins and ends to make sure they match. Also, I pair them up when I do this so I know for sure that I have the right things included in each begin end statement. SO I number each beginin normal counting order (1,2,3...), then as I get to each end, I use the number of the last begin statement that didn't already have an end statement.Sort of like inthe pattern shown below:

Begin 1
Begin 3
Begin 3
End 3
Begin 4
End 4
End 2
End 1

Usually if you have a problem where you get unexpected results, you have one of your end statements inthe wrong place and some statements are running that shouldn;t be in that group of code. Also, It's really easy to not get the begins and ends to match up.

When I write code, I try to be really good about putting inthe end statement at the time I write the begin statement, that makes it easier to makes sure I get them all and that they are inthe right place. Then I put the code in between the Begin and end.

 
Just tried that it didnt work..... just figured it out though was missing a closing parentheses after VALUES (@TransactionID,@AssociationID,@JEDate,@JEAccrue,@JEReverseDate,@JEReference,GetDate(),@JEEnteredUserID

thanks for your help though
 
Thank you SQLSister i will keep that in mind.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top