日期:2014-05-17 浏览次数:20575 次
create proc GetName
@Id int,
@Sex varchar(10)
as
declare @ReturnVar varchar(10)
select @ReturnVar=CustomerName from Customer
where CustomerId=@Id and Sex=@Sex
return @ReturnVar
use TestForProc
go
declare @Id int, @Sex varchar(10), @Name varchar(10)
set @Id=14
set @Sex='male'
exec @Name=GetName @Id, @Sex
select @Name
/*table: Customer*/
create table Customer
(
CustomerID int not null primary key,
CustomerName varchar(10),
)
/*some table contents:*/
CustomerID CustomerName Sex
4 London male
6 Mannheim famle
7 Strasbourg famle
8 Madrid famle
10 Tsawassen male
11 Londonmale male
14 Bern male
create proc GetName
@Id int,
@Sex varchar(10)
as
declare @ReturnVar varchar(10)
select @ReturnVar=CustomerName from Customer
where CustomerId=@Id and Sex=@Sex
return @ReturnVar --问题出现在这一行. 存储过程的RETURN值是一个整数类型。你这儿RETURN的是字符型。所以从字符型(Bern)转换成整型时就报错了