SELECT query for fetching all user-created database names as a comma separated value

Bandi
Posted by Bandi under Sql Server category on | Points: 40 | Views : 233
select 
stuff(
(select ', ' + name
from sys.databases
where database_id > 4
order by name
FOR XML PATH('')
)
, 1, 2, '') as DBnamelist;


output:

DBNameList 
Database1,Database2,Database3,AdventureWorks,ReportServer$SQLSERVER,DatabaseName4

Comments or Responses

Login to post response