1. How to obtain the value returned by return for a stored procedure
(1 ):Return returns a value.
Create procedure testreturn
As
Return 145
Go
-- Query calls in Analyzer
-- Declare @ RC int
-- Exec @ rc = singlevalue
-- Select @ RC
(2 ):Output Return Value
Create procedure testoutput
@ P1 int,
@ P2 int output,
@ P3 int output,
@ P4 varchar (10) Output
As
Select @ P2 = @ P1 * 2
Select @ P3 = @ P1 * 3
Select @ P4 = 'sfdsdfsdf'
Go
-- Query calls in Analyzer
-- Declare @ p2_output int
-- Execute testoutput 4, @ p2_output output
-- Select @ p2_output
-- =========================================== --
-- Declare @ p2_output int, @ p3_output int
-- Execute testoutput 4, @ p2_output output, @ p3_output output
-- Select @ p2_output, @ p3_output
(3 ):Return table
Create procedure tabletestsss
As
Declare @ ordershippertab table (col1 varchar (80), col2 varchar (80 ))
Insert @ ordershippertab values ('11', '12 ')
Insert @ ordershippertab values ('21', '22 ')
Insert @ ordershippertab values ('31', '32 ')
Insert @ ordershippertab values ('42', '42 ')
Select * From @ ordershippertab
Go
-- call in query analyzer
-- Create Table # T (col1 varchar (10), col2 varchar (10 ))
-- insert # T exec tabletestsss
-- select * from # T
-- drop table # T
2. how can I determine whether the SQL Server transaction is successfully executed?
use the system constant @ error to judge the value after each SQL statement is executed:
begin transaction
Delete...
If @ error <> 0
begin
rollback transaction
return
end
insert...
If @ error <> 0
begin
rollback transaction
return
end
commit transaction