--查询所有列 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