求助!这个存储过程出错:
表结构:
id intFName nvarchar(50)FSalary decimal(18, 0)
--创建有[输出参数] [输入参数]的存储过程;use AdventureWorks;gocreate proc selectEmployeeNameById @id int =1 , @N nvarchar(50)= null as select @N =t.FName from dbo.tee as t where (t.id=@id); return @N;
--运行 存储过程 ;declare @Name nvarchar(50);exec @Name= selectEmployeeNameById 2;print @Name;
消息 245,级别 16,状态 1,过程 selectEmployeeNameById,第 6 行在将 nvarchar 值 '小李' 转换成数据类型 int 时失败。
--创建有[输出参数] [输入参数]的存储过程;use AdventureWorks;gocreate proc selectEmployeeNameById @id int =1 , @N nvarchar(50)= null outputas select @N =t.FName from dbo.tee as t where (t.id=@id); return 0;
[解决办法]
return 返回的是int,改用ouput吧
[解决办法]
测试数据
CREATE TABLE tee( [id] INT NOT NULL PRIMARY KEY, FName nvarchar(50), FSalary decimal(18, 0))INSERT INTO teeSELECT 1,'A',500.00 UNION ALLSELECT 2,'B',600.00 UNION ALLSELECT 3,'C',700.00SELECT * FROM teeAlter proc selectEmployeeNameById @id int , @N nvarchar(50) OUTPUT AS begin SET @N=(select FName from tee where [id]=@id) ENDreturn 0 --运行 存储过程 ;declare @Name nvarchar(50)exec selectEmployeeNameById 2 ,@Name OUTPUTprint @Name/*------------------------declare @Name nvarchar(50)exec selectEmployeeNameById 2 ,@Name OUTPUTprint @Name------------------------*/B
[解决办法]