在将 varchar 值 转换成数据类型 int 时失败

越过越咸 2009-09-22 05:43:25
create proc proc_kindName
(
@kind1 int,
@kind2 int,
@kind3 int,
@kind4 int,
@str varchar(500) output
)
as
if @kind1<>0
set @str=(select kindName from kind1 where auto_id=@kind1)+','
if @kind2<>0
set @str=@str+(select kindName from kind2 where auto_id=@kind2)+','
if @kind3<>0
set @str=@str+(select kindName from kind3 where auto_id=@kind3)+','
if @kind4<>0
set @str=@str+(select kindName from kind4 where auto_id=@kind4)
return ltrim(rtrim(@str))
go

declare @pp nvarchar(500);
exec proc_kindName 20,143,157,157,@pp output
select @pp
...全文
737 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
越过越咸 2009-09-25
  • 打赏
  • 举报
回复
嗯 谢谢各位的帮助 已结贴
越过越咸 2009-09-25
  • 打赏
  • 举报
回复
create proc proc_kindName
(
@kind1 int,
@kind2 int,
@kind3 int,
@kind4 int,
@str varchar(500) output
)
as
if @kind1 <>0
set @str=(select kindName from kind1 where auto_id=@kind1)+','
if @kind2 <>0
set @str=@str+(select kindName from kind2 where auto_id=@kind2)+','
if @kind3 <>0
set @str=@str+(select kindName from kind3 where auto_id=@kind3)+','
if @kind4 <>0
set @str=@str+(select kindName from kind4 where auto_id=@kind4)
return ltrim(rtrim(@str))
go
SQL77 2009-09-22
  • 打赏
  • 举报
回复
create proc proc_kindName
(
@kind1 int,
@kind2 int,
@kind3 int,
@kind4 int,
@str varchar(500) output
)
as
if @kind1 <>0
set @str=(select kindName from kind1 where auto_id=@kind1)+','
if @kind2 <>0
set @str=@str+(select kindName from kind2 where auto_id=@kind2)+','
if @kind3 <>0
set @str=@str+(select kindName from kind3 where auto_id=@kind3)+','
if @kind4 <>0
set @str=@str+(select kindName from kind4 where auto_id=@kind4)
return
-->SELECT ltrim(rtrim(@str))
go

declare @pp nvarchar(500);
exec proc_kindName 20,143,157,157,@pp output
select @pp
jia_guijun 2009-09-22
  • 打赏
  • 举报
回复
create proc proc_kindName 
(
@kind1 int,
@kind2 int,
@kind3 int,
@kind4 int,
@str varchar(500) output
)
as
if @kind1 <>0
select @str=kindName+',' from kind1 where auto_id=@kind1
if @kind2 <>0
select @str=@str+kindName+',' from kind2 where auto_id=@kind2
if @kind3 <>0
select @str=@str+kindName+',' from kind3 where auto_id=@kind3
if @kind4 <>0
select @str=@str+kindName from kind4 where auto_id=@kind4
GO
lg314 2009-09-22
  • 打赏
  • 举报
回复
return改成set或者弄成函数
7761098 2009-09-22
  • 打赏
  • 举报
回复

create proc proc_kindName
(
@kind1 int,
@kind2 int,
@kind3 int,
@kind4 int,
@str varchar(500) output
)
as
if @kind1 <>0
set @str=’(select kindName from kind1 where auto_id=‘’‘’‘+@kind1+’‘’‘’),'
if @kind2 <>0
set @str=@str+‘(select kindName from kind2 where auto_id=’‘’‘’+@kind2‘‘’‘’),'
if @kind3 <>0
set @str=@str+’(select kindName from kind3 where auto_id=‘’‘’‘+@kind3+’‘’‘’),'
if @kind4 <>0
set @str=@str+‘(select kindName from kind4 where auto_id=‘’‘’’+@kind4+‘‘’‘’)’
return ltrim(rtrim(@str))
go

declare @pp nvarchar(500);
exec proc_kindName 20,143,157,157,@pp output
select @pp
jia_guijun 2009-09-22
  • 打赏
  • 举报
回复
create proc proc_kindName 
(
@kind1 int,
@kind2 int,
@kind3 int,
@kind4 int,
@str varchar(500) output
)
as
if @kind1 <>0
select @str=kindName+',' from kind1 where auto_id=@kind1
if @kind2 <>0
select @str=@str+kindName+',' from kind2 where auto_id=@kind2
if @kind3 <>0
select @str=@str+kindName+',' from kind3 where auto_id=@kind3
if @kind4 <>0
set @str=@str+kindName from kind4 where auto_id=@kind4
select ltrim(rtrim(@str))
go
xiequan2 2009-09-22
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 ycagri 的回复:]
只能return int类型的

如果想返回字符类型,使用  output
[/Quote]..
ycagri 2009-09-22
  • 打赏
  • 举报
回复
你把return去掉就可以了
ycagri 2009-09-22
  • 打赏
  • 举报
回复
只能return int类型的

如果想返回字符类型,使用 output
越过越咸 2009-09-22
  • 打赏
  • 举报
回复
自己先顶 在线等待...................

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧