Error history-SQL proc

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.