--create a test table to create a stored procedure create table customers (cid int , cname varchar(30),cage int,ccity varchar(30),cstate varchar(30)) --Insert 4 Records insert into customers select 1,'c1',20,'city_1','state-1' insert into customers select 2,'c2',20,'city_2','state-2' insert into customers select 3,'c3',20,'city_3','state-3' insert into customers select 4,'c4',20,'city_4','state-4' -- Test how many records Select * from customers -- create a procedure to wrap the basic select statement above create procedure pr_customers as select * from customers -- basic syntax :execute procedure exec pr_customers
Results :
--2) procedure with return parameter: every procedure returns an integer value , by default the return value is 0 for successful execution. execute the above procedure and print the return value | -- Syntax to execute a procedure to get the return value declare @ret int -- declare a variable to capture the return value exec @ret = pr_customers select @ret as return_value -- this is the return value of the procedure
| so , default return value of 0 means its succesful. create another stored procedure with a sql statement to generate error with 100/0 which results an erro | create proc pr_customers_with_ret as select 100/0 |
No comments:
Post a Comment