1.
use TestForProcGOdeclare @Id int, @Sex varchar(10), @Name varchar(10)set @Id=14 set @Sex='male'exec getid @Id output, @Sex, @Name outselect @Id as Id, @Name as Name
Wrongs:
Set @ ID = 14, set @ sex = 'male'
Set @ ID = 14, @ sex = 'male'
2.
ALTER proc [dbo].[getid_return]@Id int,@Sex varchar(10)asdeclare @ReturnVar varchar(10)select @ReturnVar=CustomerName from Customerwhere CustomerId=@Id and Sex=@Sexreturn @ReturnVar
Error: Return @ returnvar
The return value can only be an integer. If a varchar value is returned, an error is returned.
There are two ways to modify. One is to change return to seleclt, and the other is to remove return and directly use output to define variables.
Note:
After changing to select @ returnvar, run
@ Name = getid_return @ var, @ VaR
The values in the table will be output immediately. This is not recommended because the output header is null. To facilitate the definition, the output variable should be defined as the output type.
3.
declare @Id int, @Sex varchar(10), @Name varchar(10)set @Id=14set @Sex='male'exec getid_return @Id, @Sex, @Name outselect @Name as Name
Error:
In Proc, @ name is defined as varchar out type, but input:
exec getid_return @Id, @Sex, @Name
In this case, the output result is not obtained. It should be changed to Exec getid_return! ID, @ sex, @ nameOut