Home  >  Article  >  Database  >  表的字段名转为逗号相隔的字符串

表的字段名转为逗号相隔的字符串

WBOY
WBOYOriginal
2016-06-07 14:55:091058browse

将表的所有字段名转成 字段1,字段2,字段3 这样的形式,中间用','相隔 当前用在sql2008 其他数据库未测试 无 select replace(replace(stuff((Select ',',NameFrom SysColumns Where id=Object_Id('表名') and name not in ('Id')for xml path('')),1,1,''),'

将表的所有字段名转成 "字段1,字段2,字段3" 这样的形式,中间用','相隔
当前用在sql2008
其他数据库未测试
select 
replace(
	replace(
		stuff(
			(
				Select ',',Name
				From SysColumns 
				Where id=Object_Id('表名') and 
				name not in ('Id')
				for xml path('')
			),
			1,
			1,
			''),
		'<Name>',
		''),
	'</Name>',
	''
)
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn