Mssql dynamic where clause within a stored procedure?

Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
Hi mssql monsters, and monsters = )

The situation is this: fat is a stored procedure, there are several temporary tables, and everything. At the end of the procedure creates a result table with the desired data

DECLARE @search table ( .... )
INSERT INTO @search (...) select ... union select ....

I hranicu parameter @a where [varchar](500)

the parameter looks like this:
SET @where = 'SELECT * FROM @search WHERE id > 0 AND name like "%apple%"'

and at the end of the procedure I'm trying to do this:


BUT as you know, the exec creates the context and the code does not see lying. table Demian Smith.

Question — is it possible to do so in order to see the table(@search) inside exec?

How can you choose from this hranilki anything? (if you try to make the outside a temporary table and do
INSERT INTO @newTemp exec [dbo].[search_proc] — gives an error about nested exec. (this procedure is already running, and insert them into table — time)
by | 27 views

1 Answer

0 like 0 dislike
but if instead of declaring a variable
declare @search table (....)
use local temporary tables
create table #seatch (....)
insert into #search (....) select from...
select @where='select * from #search where ..'
exec (@where)

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
110,608 questions
257,187 answers
40,796 users