环境:xp/sql server2005create table users(user_Name varchar(20),User_nb varchar(20),user_Nc nvarchar(20))
--drop table users
--select * from users
insert into users values('xjs','xjs','禁药')
--drop proc useproc
create proc useproc
@msg nvarchar(20) output
as
begin
select @msg = user_Nc from users where user_Name='xjs'
print(@msg)
return @msg
enddeclare @msg nvarchar(20)
exec useproc @msg居然报下面的错误,为什么???????????禁药
消息 245,级别 16,状态 1,过程 useproc,第 7 行
在将 nvarchar 值 '禁药' 转换成数据类型 int 时失败。
@msg nvarchar(20) output
as
begin
select @msg = user_Nc from users where user_Name='xjs'
--print(@msg)
--return @msg
end
godeclare @msg nvarchar(20)
exec useproc @msg output
select @msg
print(@msg)
return @msg
exec useproc @msg output
select @msg
在将 nvarchar 值 '禁药' 转换成数据类型 int 时失败。
这个错误就是因为你使用了return @msg
@msg是字符串 但是存储过程只能返回INT类型
go
if exists(select * from sysobjects where id=object_id('users'))
begin
drop table users
drop proc useproc
end
create table users(user_Name varchar(20),User_nb varchar(20),user_Nc nvarchar(20))
--drop table users
--select * from users
insert into users values('xjs','xjs','禁药')
--drop proc useproc
go ---这里要加上 go
create proc useproc
@msg nvarchar(20) output
as
begin
select @msg = user_Nc from users where user_Name='xjs'
print(@msg)
--return @msg 存储过程里不能有return语句
end
go
declare @msg nvarchar(20)
exec useproc @msg output
select @msg