I’m trying to make a select like this:
DECLARE @ContentIDs VARCHAR(MAX);
SELECT @ContentIDs = 'e28faa48-adea-484d-9d64-ba1e1c67eea3,8338A6DE-8CDF-4F52-99CE-62E2B107FF97'
SELECT * FROM [Content] WHERE [ID] IN (@ContentIDs)
It only returns the content with the first UNIQUEIDENTIFIER.
How can I retrieve all rows?
You could
use dynamic SQL to generate the query but would need to be sure the list was sanitised
use a split function to parse the list and add each entry as a row into a table variable which you then join on that or
use
SELECT * FROM [Content] WHERE @ContentIDs like '%' + cast([ID] as varchar(36)) + '%'this will force a full scan but if you are matching many rows this might not matter. (Edit but if you are matching many rows the comparison string will likely be huge!)Option 2 would generally be my preferred approach. Or you could use a CTE to do something similar (Based on approach here)