If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > converting from sql server to mysql?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-26-04, 12:59
xayavon xayavon is offline
Registered User
 
Join Date: Dec 2003
Posts: 23
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
Reply With Quote
  #2 (permalink)  
Old 01-26-04, 13:34
aus aus is offline
Registered User
 
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.
Reply With Quote
  #3 (permalink)  
Old 01-26-04, 14:12
xayavon xayavon is offline
Registered User
 
Join Date: Dec 2003
Posts: 23
aus,
Thanks a lot. That was so much easier then sql server.

xayavon
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On