Solved

Multiple insert statements in the same stored procedure

Posted on 2006-11-09
2
485 Views
Last Modified: 2008-02-01
Hello Experts,
I am trying to build a stored procedure in MySQL that runs 1 insert statement, get the identity, then runs another insert statement.
Here is my procedure:
CREATE PROCEDURE usp_sch_insert_subevent_attendees_dev(
      IN transaction_key int,
      IN attendee_key int,
      IN sub_event_key int,
      IN event_key int,
      IN subevent_comments varchar(500),
      IN fee int,
      IN comp int,
      IN comp_amt int,
      IN comp_code varchar(20),
      IN pmt_type char(10)
 )

BEGIN


INSERT INTO sch_invoice
(
transaction_key,
attendee_key,
sub_event_key,
fee,
comp,
comp_amt,
pmt_type
)
VALUES
(
transaction_key,
attendee_key,
sub_event_key,
fee,
comp,
comp_amt,
pmt_type
)


DECLARE i_key int
SET i_key = last_insert_id()



INSERT INTO sch_subevent_attendees
(
      attendee_key,
      sub_event_key,
      event_key,
      subevent_comments,
      fee,
      comp,
      comp_amt,
      comp_code,
      transaction_key,
      invoice_key,
      pmt_type
)
VALUES
(
      attendee_key,
      sub_event_key,
      event_key,
      subevent_comments,
      fee,
      comp,
      comp_amt,
      comp_code,
      transaction_key,
      i_key,
      pmt_type
)

END;

And here is the very vague error I'm getting:
Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT INTO sch_invoice
(
transaction_key,
attendee_key,
sub_event_key,
fee,
com' at line 14
(16 ms taken)

If I take one of the insert statements out, it runs OK. Is it not possible to do this in MySQL 5.0.22-standard?
Thanks
Chad
0
Comment
Question by:ChadMarsh
2 Comments
 
LVL 33

Accepted Solution

by:
snoyes_jw earned 500 total points
Comment Utility
You need ; after each insert and declaration.  You'll need to change the delimiter to something other than ; using the DELIMITER statement, so that MySQL will process the whole thing as one stored procedure.  See http://dev.mysql.com/doc/refman/5.0/en/create-procedure.html for examples.
0
 
LVL 2

Author Comment

by:ChadMarsh
Comment Utility
Thanks a lot. That worked perfectly.
Chad
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now