MySQL stored procedure variables

A few months ago we wrote a mammoth we application which had an SQL Express DB. We used stored procedures, and after writing 170 of them(I didn't write all of them of course), I was quite used to the way that variables and so on worked in SQL Server.

We've started a new project where the DB is MySQL 5. Again we are using stored procedures, but variables work differently.

Setting a variable in SQL Server

DECLARE @oldPageGUID uniqueidentifier;
SET @oldPageGUID = (SELECT mPage.id FROM mPage WHERE mPage.title = @passedtitle);

Setting a variable in MySQL Server

DECLARE dateAdded TIMESTAMP;
SELECT lusers.dateadded INTO dateAdded FROM lusers WHERE lusers.id= id;

You can see that setting the value of the variable is done completely differently (MySQL Docs for SELECT ... INTO Statement). Two other things that confused me for a while was that there is no character prefixed to the variables in MySQL as in SQL server (@) and that there is no uniqueidentifier data-type for GUIDs

3 Comments

  1. Posted May 20, 2008 at 10:51 am | Permalink

    Thanks!!

    I know you wrote this soo long ago.

    But i’ve been hunting the net for a full day trying to work this little problem out.. very strange syntax!

    Ta

    Dave

  2. Milk Man
    Posted June 15, 2008 at 5:48 pm | Permalink

    Awesome. Thank you.

  3. Posted December 11, 2009 at 5:05 pm | Permalink

    Very helpful. Thanks!

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*