Dileep
Dileep

Reputation: 73

Use Dynamic Query in a Procedure and call that procedure in a select statement in SQL Server

I need to execute a dynamic query in SQL Server and show the result in a select query.

Since, we cannot use dynamic queries in functions, we have written a stored procedure to return the dynamic query value.

But how can i call my stored procedure in a select query.

Upvotes: 0

Views: 117

Answers (1)

M.Ali
M.Ali

Reputation: 69594

You normally would use the key word EXEC or EXECUTE to call a stored procedure.

yet there is a way of selecting data from a stored procedure using OPENQUERY.

SELECT  * FROM 
OPENQUERY(SERVERNAME, 'EXECUTE Proc_Name @parameters')

Upvotes: 1

Related Questions