sql server 2005 存储过程里定义一个变量取很多值怎么做 :::急
alterprocaasdeclare@idsselectproc_idfromLI63_ProCategoriesorderbyproc_iddescprint@ids...
alter proc a
as
declare @ids
select proc_id from LI63_ProCategories order by proc_id desc
print @ids
注:
select proc_id from LI63_ProCategories order by proc_id desc
会取出很多值
怎么做将他们都取出来 展开
as
declare @ids
select proc_id from LI63_ProCategories order by proc_id desc
print @ids
注:
select proc_id from LI63_ProCategories order by proc_id desc
会取出很多值
怎么做将他们都取出来 展开
3个回答
展开全部
1.游标
alter proc a
as
declare @ids
declare c1 cursor for
select proc_id from LI63_ProCategories order by proc_id desc
open c1
fetch next from c1 into @ids
while @@fetch_status=0
begin print @ids fetch next from c1 into @ids end
close c1
deallocate c1
2.字符串组
alter proc a
as
declare @ids varchar(1000)
select @ids=isnull(@ids,'')+convert(varchar,proc_id)+',' from LI63_ProCategories order by proc_id desc
print @ids
alter proc a
as
declare @ids
declare c1 cursor for
select proc_id from LI63_ProCategories order by proc_id desc
open c1
fetch next from c1 into @ids
while @@fetch_status=0
begin print @ids fetch next from c1 into @ids end
close c1
deallocate c1
2.字符串组
alter proc a
as
declare @ids varchar(1000)
select @ids=isnull(@ids,'')+convert(varchar,proc_id)+',' from LI63_ProCategories order by proc_id desc
print @ids
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select proc_id from LI63_ProCategories order by proc_id desc,这个语句已经将所有的值都取出来了,如果你是想使用变量产生“value1,value2,value3....”这样的格式的话,可以使用下面方法
declare @ids nvarchar(max)
set @ids=''
select @ids=@ids + proc_id +',' from LI63_ProCategories order by proc_id desc
print @ids
declare @ids nvarchar(max)
set @ids=''
select @ids=@ids + proc_id +',' from LI63_ProCategories order by proc_id desc
print @ids
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
alter proc a
as
declare @ids
set @ids=''
select @ids=@ids+','+proc_id from LI63_ProCategories order by proc_id desc
print @ids
as
declare @ids
set @ids=''
select @ids=@ids+','+proc_id from LI63_ProCategories order by proc_id desc
print @ids
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询