sql 获取列名

--查询所有列
select  name from syscolumns where id=OBJECT_ID('PTS_ProjectTask')
--列转为行
GetColumnJoin 'ProjectTask'

alter proc GetColumnJoin
@TableName nvarchar(50)
as
begin
    declare @tempStr nvarchar(50),@ResultStr nvarchar(max)
    set @tempStr=''
    set @ResultStr=''
    declare Columns_Cursor cursor for
        select  name from syscolumns where id=OBJECT_ID(@TableName)
    open Columns_Cursor
    fetch next from Columns_Cursor into  @tempStr
    while(@@FETCH_STATUS=0)
        begin
            set @ResultStr=@ResultStr+','+@tempStr
            fetch next from Columns_Cursor into  @tempStr
        end
    print @ResultStr
    close Columns_Cursor 
    deAllocate Columns_Cursor
end

 

posted @ 2014-06-18 19:12  kedarui  阅读(869)  评论(0编辑  收藏  举报