现在的位置: 首页 > 综合 > 正文

取得字段集

2012年02月26日 ⁄ 综合 ⁄ 共 347字 ⁄ 字号 评论关闭

alter function fn_GetColumns
(
@TableName varchar(max)
)
returns varchar(max)
as
begin
declare @cols varchar(max);
with cols
as ( select columns.name
from sys.columns
join sys.objects on sys.columns.object_id = sys.objects.object_id
and objects.name = @TableName
)
select @cols = ( stuff(( select ',' + name
from cols t
for
xml path('')
), 1, 1, '') )

return @cols
end

select dbo.fn_GetColumns('Student')

抱歉!评论已关闭.