Unix Technical Forum

Returning value after insert

This is a discussion on Returning value after insert within the MySQL General forum forums, part of the MySQL category; --> Hi, Is there a way of after a select statement having a return value for a determined field ? ...


Go Back   Unix Technical Forum > Database Server Software > MySQL > MySQL General forum

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 09:25 PM
Deckard
 
Posts: n/a
Default Returning value after insert

Hi,

Is there a way of after a select statement having a return value for a
determined field ?

For example, after this:
INSERT INTO wl_users(name, email, password) VALUES('Deckard',
'ml@wordlife.eu', 'blabla')

having the name returning without having to make a subsequent select.

Any help would be appreciated.

Best Regards,
Deckard

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 09:26 PM
Price, Randall
 
Posts: n/a
Default RE: Returning value after insert

You could use a stored procedure to do the INSERT and then return the
value from SELECT statement. For example,

DELIMITER $$;
DROP PROCEDURE IF EXISTS `test`.`spINSERTandSELECT`$$

CREATE PROCEDURE `test`.`spINSERTandSELECT` (IN strFirstName
VARCHAR(20),
IN strLastName VARCHAR(20))
BEGIN
INSERT INTO
usernames (FirstName, LastName)
VALUES
(strFirstName, strLastName);

SELECT CONCAT(strFirstName, " ", strLastName);
END$$

DELIMITER ;$$


Then call the stored procedure as follows:

mysql> use test;
Database changed
mysql> call spINSERTandSELECT("John", "Doe");
+----------------------------------------+
| CONCAT(strFirstName, " ", strLastName) |
+----------------------------------------+
| John Doe |
+----------------------------------------+
1 row in set (0.06 sec)

Query OK, 0 rows affected (0.06 sec)

mysql>

Hope this helps.

Randall Price

Microsoft Implementation Group
Secure Enterprise Computing Initiatives
Virginia Tech Information Technology
1700 Pratt Drive
Blacksburg, VA 24060

Email: Randall.Price@vt.edu
Phone: (540) 231-4396



-----Original Message-----
From: Deckard [mailto:ml@wordlife.eu]
Sent: Tuesday, October 03, 2006 11:40 AM
To: mysql@lists.mysql.com
Subject: Returning value after insert

Hi,

Is there a way of after a select statement having a return value for a
determined field ?

For example, after this:
INSERT INTO wl_users(name, email, password) VALUES('Deckard',
'ml@wordlife.eu', 'blabla')

having the name returning without having to make a subsequent select.

Any help would be appreciated.

Best Regards,
Deckard


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:
http://lists.mysql.com/mysql?unsub=Randall.Price@vt.edu

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:06 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com