Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2003
    Posts
    23

    Unanswered: converting from sql server to mysql?

    Hi,
    I'm new to mysql and I'm trying to convert this routine that is written for sql server to mysql. This routine updates a record if it exists and adds a record if it does not exists. If anybody can help, please do so. Thanks in advance for your time.

    -- update if already exist
    IF (@pk_ID <> 0 AND ( EXISTS (SELECT * FROM table1 WHERE pk_ID=@pk_ID)) )
    BEGIN
    UPDATE table1 SET
    value1=@value1,
    value2=@value2
    WHERE pk_ID=@pk_ID
    END
    ELSE
    BEGIN
    INSERT INTO table1
    (value1, value2)
    VALUES
    (@value1, @value2)
    END

    Thanks,

    xayavon

  2. #2
    Join Date
    Oct 2003
    Location
    Denver, Colorado
    Posts
    137

    Re: converting from sql server to mysql?

    Just use REPLACE, like this:

    Code:
    REPLACE table1 SET pk_ID = @pk_ID, value1 = @value1, value2 = @value2;
    It will handle an existing entry by updating it or insert a new entry.

  3. #3
    Join Date
    Dec 2003
    Posts
    23
    aus,
    Thanks a lot. That was so much easier then sql server.

    xayavon

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •