Skip to content
Advertisement

Execute procedure in statement in NOT IN()

I have the following stored procedure in SQL Server

How can I call it in a statement NOT IN?

Error example:

Note: I’m not interested in rewriting it more efficient. I just want to know how can I call the procedure within the NOT IN parameters. I get an error

Incorrect syntax near ‘)’

on the closing parameters of the EXEC.

I’m using SQL Server Management Studio v17.1

Advertisement

Answer

You can’t directly. This is why you should use a table valued function rather than a stored procedure.

With a stored procedure, you would need to create a local table, exec() into the table, and then use the temporary table for the query.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement