取得字段集

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')

原文地址:https://www.cnblogs.com/qanholas/p/2462417.html