1

Topic: In line some codes of establishments. How to use them in Select query?

In stored procedure I transfer a line containing of some codes of establishments: @s = ' 1118, 1119, 1108 '.
As in . To procedure, using this line, to make such or to it similar request:
select *
from lpu
where lpuid in (1118, 1119, 1108)

2

Re: In line some codes of establishments. How to use them in Select query?

seg856;
I.e. the code at you ?

3

Re: In line some codes of establishments. How to use them in Select query?

- To transfer not a line, and a tabular variable
- Inside pr-ry  a line in the table / a variable and to use join

4

Re: In line some codes of establishments. How to use them in Select query?

declare @IDs nvarchar (max) = ' 1,5,9,11,3,2 ';
--1 variant
select *
from lpu
where lpuid in (
select a.b.value (' (text() [1] ', ' int ')
FROM (VALUES (CAST (' <r> ' +REPLACE (@IDs, ', ', ' </r> <r> ') + ' </r> ' AS XML))) X (X)
CROSS APPLY X.nodes ('/r ') a (b)
)
--2 
set @sql varchar (max) = ' select * from lpu where lpuid in (' + @IDs + ')'
exec (@sql)

5

Re: In line some codes of establishments. How to use them in Select query?

Rankatan;
Tin what...
It is necessary to use true types for the data, instead of to be perverted.

6

Re: In line some codes of establishments. How to use them in Select query?

seg856 wrote:

In stored procedure I transfer a line containing of some codes of establishments: @s = ' 1118, 1119, 1108 '.
As in . To procedure, using this line, to make such or to it similar request:
select *
from lpu
where lpuid in (1118, 1119, 1108)

select *
from lpu
where ', ' +replace (@s, ' ', ") + ', ' like ' %, ' +lpuid + ', % ';

7

Re: In line some codes of establishments. How to use them in Select query?

iap wrote:

it is passed...

select *
from lpu
where ', ' +replace (@s, ' ', ") + ', ' like ' %, ' +lpuid + ', % ';

select *
from lpu
where ', ' +replace (@s, ' ', ") + ', ' like ' %, ' +lpuid + ', % ';

select *
from lpu
where ', ' +replace (@s, ' ', ") + ', ' like ' %, ' +cast (lpuid as varchar) + ', % ';