maqskywalker
asked on
t-sql display query result as list of comma separated values.
I'm using the Employees table from the Northwind Sql Server database.
It looks like this:
If my input is this
DECLARE @LastName varchar(50)
SET @LastName = 'Davolio,Fuller,Leverling, Peacock,Bu chanan,Suy ama,King,C allahan,Do dsworth'
what is the syntax to get this result. Which is a list of the EmployeeIDs of the last names I input.
It looks like this:
If my input is this
DECLARE @LastName varchar(50)
SET @LastName = 'Davolio,Fuller,Leverling,
what is the syntax to get this result. Which is a list of the EmployeeIDs of the last names I input.
ASKER
Using sql server 2008. the datatype for the string list is varchar(2500) that's the limit we are setting.
Isn't this pretty much a duplicate of your previous question:
https://www.experts-exchange.com/questions/29134449/T-sql-working-with-comma-separated-string-in-where-clause.html
https://www.experts-exchange.com/questions/29134449/T-sql-working-with-comma-separated-string-in-where-clause.html
ASKER
slightwv, no it's slightly different.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks. Nice solution.
You can use "standard" XML concat method of the lookup results, but it's high overhead, and a bit obscure.
What version of SQL? 2008/2012/2016/etc.
What's the most names you'd ever put in the list?