I have two tables orders and company. Company table contains unique company id and company name.
Orders table has two column, one is orderid and other is companyIDs. CompanyIds can be multiple comma separated values.
I am using following query to get the company name corresponding to each company id of orders table.
SELECT
(SELECT GROUP_CONCAT(cmp.cmpny_name)
FROM company cmp
WHERE FIND_IN_SET(cmp.CompanyID, odr.companyIDs)
) AS company
FROM orders odr
It works perfectly fine in Mysql but not in sql server as these keywords are not supported in sql server and I haven' worked on sql server much so please help me to find correct way to accomplish this.
Thanks
On search, I have got some keywords like stuff for group concat but not able to use properly. Not able to find an equivalent of the find_in_set for sql server.
SELECT
(SELECT GROUP_CONCAT(cmp.cmpny_name)
FROM company cmp
WHERE FIND_IN_SET(cmp.CompanyID, odr.companyIDs)
) AS company
FROM orders odr
Not working in sql server
GROUP_CONCAT
would beSTRING_AGG
. As the the latter, depends on the requirement. – Larnu