You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/t-sql/language-elements/return-transact-sql.md
+9-10Lines changed: 9 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,7 +36,6 @@ ms.author: jroth
36
36
## Syntax
37
37
38
38
```syntaxsql
39
-
40
39
RETURN [ integer_expression ]
41
40
```
42
41
@@ -62,7 +61,7 @@ RETURN [ integer_expression ]
62
61
### A. Returning from a procedure
63
62
The following example shows if no user name is specified as a parameter when `findjobs` is executed, `RETURN` causes the procedure to exit after a message has been sent to the user's screen. If a user name is specified, the names of all objects created by this user in the current database are retrieved from the appropriate system tables.
64
63
65
-
```
64
+
```sql
66
65
CREATE PROCEDURE findjobs @nm sysname =NULL
67
66
AS
68
67
IF @nm IS NULL
@@ -82,10 +81,10 @@ ELSE
82
81
### B. Returning status codes
83
82
The following example checks the state for the ID of a specified contact. If the state is Washington (`WA`), a status of `1` is returned. Otherwise, `2` is returned for any other condition (a value other than `WA` for `StateProvince` or `ContactID` that did not match a row).
84
83
85
-
```
84
+
```sql
86
85
USE AdventureWorks2012;
87
86
GO
88
-
CREATE PROCEDURE checkstate @param varchar(11)
87
+
CREATE PROCEDURE checkstate @param VARCHAR(11)
89
88
AS
90
89
IF (SELECT StateProvince FROMPerson.vAdditionalContactInfoWHERE ContactID = @param) ='WA'
91
90
RETURN 1
@@ -96,8 +95,8 @@ GO
96
95
97
96
The following examples show the return status from executing `checkstate`. The first shows a contact in Washington; the second, contact not in Washington; and the third, a contact that is not valid. The `@return_status` local variable must be declared before it can be used.
98
97
99
-
```
100
-
DECLARE @return_status int;
98
+
```sql
99
+
DECLARE @return_status INT;
101
100
EXEC @return_status = checkstate '2';
102
101
SELECT'Return Status'= @return_status;
103
102
GO
@@ -115,8 +114,8 @@ GO
115
114
116
115
Execute the query again, specifying a different contact number.
117
116
118
-
```
119
-
DECLARE @return_status int;
117
+
```sql
118
+
DECLARE @return_status INT;
120
119
EXEC @return_status = checkstate '6';
121
120
SELECT'Return Status'= @return_status;
122
121
GO
@@ -133,8 +132,8 @@ GO
133
132
134
133
Execute the query again, specifying another contact number.
0 commit comments