1

Topic: where in

Good afternoon!
For example there is table A of two fields:
id int (identifier)
fio nvarchar (50) (surname)
In other table in the field ids nvarchar (MAX) are stored the list id through a separator a comma, for example ' 1,5,18'
The task: to make function returning line with surnames through a separator-comma
Problem: in functions it is impossible to use temporary tables, wanted a line ' 1,5,18 '  in the temporary table and
select @s = s + RTRIM (A.FIO) + ', ' from ##temp inner join A on ##temp.id=A.id
It would turn out as a result for example ' Ivanov, Petrov, Sidorov,'
Wanted to cause from function EXECUTE sp_executesql - too it is impossible...
Prompt, can eat  a simple variant? That that of type select * from A where id in *** IDs ***

2

Re: where in

STRING_SPLIT (string, separator)
https://docs.microsoft.com/en-us/sql/t- … ansact-sql

3

Re: where in

caca;
Use inline-view in which will be happens  lines of values through a comma in the table-column.
Instead of IN to do JOIN "tables-columns" received on the fly with your table And
As an example - to esteem a subject
Tasks 1,2 - as much as possible close to that is necessary for you...

4

Re: where in

caca wrote:

... In other table in the field ids nvarchar (MAX) are stored the list id through a separator a comma, for example ' 1,5,18 '...

For such it is necessary to strike a bargain a ruler!
It means that the table even to 1 is not resulted. I.e. it not the table, simply heap of any data, somehow there

5

Re: where in

It is possible not , if an amount small
It is possible to add to the list of identifiers a comma at the left and on the right so that it turned out ", 5,1,3," and to search like ' %, ' + cast (id as varchar (10)) + ', %'

6

Re: where in

All many thanks!