当前位置: 数据库>sqlserver
根据表名和索引获取需要的列名的存储过程
来源: 互联网 发布时间:2014-10-04
本文导语: 代码如下: create proc p_sword_getblcolumn ( @tblName varchar(200), @fromIndex int, @toIndex int, @columnName varchar(3000) output ) as begin declare @tempColumn varchar(3000) declare @errMsg varchar(200) declare @i int set @i=1 set @columnName='' set @errMsg='' declare tempColumnCur cursor fo...
代码如下:
create proc p_sword_getblcolumn
(
@tblName varchar(200),
@fromIndex int,
@toIndex int,
@columnName varchar(3000) output
)
as
begin
declare @tempColumn varchar(3000)
declare @errMsg varchar(200)
declare @i int
set @i=1
set @columnName=''
set @errMsg=''
declare tempColumnCur cursor for
select syscolumns.name from syscolumns join sysobjects on syscolumns.id = sysobjects.id
where sysobjects.name =@tblName order by syscolumns.colorder
open tempColumnCur
fetch next from tempColumnCur into @tempColumn
while @@FETCH_STATUS=0
begin
if(@fromIndex=0 and @toIndex=0)
begin
set @columnName=@columnName+','+@tempColumn
end
if(@fromIndex=0 and @toIndex0)
begin
if(@i=@fromIndex)
set @columnName=@columnName+','+@tempColumn
end
else if(@i>=@fromIndex and @i