Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hi all, I'm having one of those days and can't for the life of me figure out how to do this within sql.I want to: select name from syslogins ....and have the output be comma delimited on one linerita, sue, bob I'd like to do within sql as am running this on 100's on servers. Can you help?Thank you!!
webfred
Master Smack Fu Yak Hacker
8781 Posts
Posted - 2009-11-02 : 12:54:08
An approach to adapt:DECLARE @EmployeeList varchar(100)SELECT @EmployeeList = COALESCE(@EmployeeList + ', ', '') + CAST(Emp_UniqueID AS varchar(5))FROM SalesCallsEmployeesWHERE SalCal_UniqueID = 1SELECT @EmployeeListComing from : http://www.sqlteam.com/article/using-coalesce-to-build-comma-delimited-stringNo, you're never too old to Yak'n'Roll if you're too young to die.
TG
Master Smack Fu Yak Hacker
6065 Posts
Posted - 2009-11-02 : 13:14:40
Here's another possible approach:
select substring(names, 3, 8000)from ( select ', ' + name from sys.syslogins for xml path('') ) as d (names)
EDIT:but your "hundreds of servers" need to be 2005 or later for this one.Be One with the OptimizerTG