Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Other SQL Server 2012 Topics
 SQL procedure Return text??

Author  Topic 

ChrisjBrown
Starting Member

8 Posts

Posted - 2014-05-25 : 16:15:43
HI,

I have an SQL procedure which enables a user to easily insert records into my database. The code is given below:

CREATE PROCEDURE add_enrollment (IN s_id CHAR(4), IN c_code CHAR(2), e_date DATE)
BEGIN
INSERT INTO enrollment
VALUES (s_id, c_code, e_date);
END

The procedure enables the user to add a new record to the enrollment table; student_id, course_code and enrollment_date. What I need it to do is have an output parameter return a string of text identifying the reason(s) for the failure. I am relatively new to SQL so I am a bit at a loss. Could anyone help?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-05-25 : 19:11:09
Use a Try/Catch block: http://msdn.microsoft.com/en-us/library/ms175976.aspx

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -