I have this column in a SQL Server table of type nvarchar
that has Id numbers of another table separated by semicolon (bad design, can't change it).
The query I am trying to run works when there is only one value in the GroupIds column however with multiple groups it fails with an error
Conversion failed when converting the nvarchar value '2;5' to data type int.
Code:
SELECT
i.Name,
i.Channel,
g.Name AS 'Group Name',
io.Name AS 'Logger Name',
io.ModuleType,
io.IpAddress
FROM
Input i
JOIN
[dbo].[Group] g ON i.GroupIds = g.Id
JOIN
[dbo].[IoModule] io ON i.IoModuleId = io.Id
ORDER BY
i.Channel, io.Name;
I have exhausted my Google skills with a few things half working but nothing giving the results I need. Ideally, I would like to see a result with the Group Names separated by commas.
Note: I need this as a one-off report from a production database. I can't create temp tables, functions or anything of that nature. The answer that this question has been tagged as duplicate is not any help. There are 42 answers from the past 10 years in that question. None of those had anything about selecting that data from a join. It may be my general lack of knowledge of joins but I am searching for an answer of basically getting my group ids in one column by group name separated by a comma.