Day 15

Quiz

1:What is the correct method to return a data value to a calling program?
A1: You should define a variable as output to return a data value to the calling program. Then you must set the variable to the value you want to pass.
create proc p1 (@x int output)
as
select @x = 1
return
2:I have the following procedure and batch, but when I run the batch, the value of @out_x is always null. What's wrong?
create procedure p1 (@x int output)
as
select @x = 1
returndeclare @out_x int
execute p1 @out_x
select @out_x
A2: The reason you are getting a null returned is that you must include the output keyword in the Execute statement as well as the procedure.
declare @out_x int
execute p1 @out_x output
select @out_x
3:In this procedure and batch, ...

Get Sams Teach Yourself Transact-SQL in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.