34,575
社区成员
发帖
与我相关
我的任务
分享
return
-->SELECT ltrim(rtrim(@str)) 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
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
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