Mssql dynamic where clause within a stored procedure?

0 like 0 dislike
11 views
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:

EXEC(@words)


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 | 11 views

1 Answer

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

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
28,875 users