How do I show a message from a stored procedure?
What is the right syntax to display a message saying whether or not rows exist?
In SQL Server it's PRINT to show a message bat in WORKBENCH...
CREATE PROCEDURE `new_proced` (
in myid int(3)
)
BEGIN
if not exists (select id from table where id = myid)
then
show message 'Row no exists';
else
show message 'Row exists';
end if;
END
Using SQL Server Management StudioExpand Stored Procedures, right-click the procedure and then select Script Stored Procedure as, and then select one of the following: Create To, Alter To, or Drop and Create To. Select New Query Editor Window. This will display the procedure definition.
:Explanation: Note: You can use literal string (enclosed in single or double quotation mark) just like we use a column name in the SELECT statement. If you use the literal string with a column then it will be displayed in every row of the query results.
The easy way is to right-click on the procedure in Sql Server Management Studio (SSMS), select 'Execute stored procedure..." and add values for the input parameters as prompted. SSMS will then generate the code to run the procedure in a new query window, and execute it for you.
Stored procedures can't "show messages". Then can return either an OUTPUT parameter OR a record set. It's up to your application to determine what to do with the results. That said, you can "print" a message which is similar to simply selecting some text: see stackoverflow.com/questions/6912102/…
Not entirely sure why you would want to do something like that, but you could do something like this: ...
then
select 'YOUR MESSAGE HERE'
else
select 'YOUR OTHER MESSAGE HERE'
end if
Or you could select 1 or 0, might be a little better...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With