Sort of ...you can pass the SQL as a Text String parameter e.g. NVARCHAR(MAX)You can then execute that within the SProc. You can useEXEC (@MySQLParameter)
but MUCH better would be to use parameterised SQL and sp_ExecuteSQL like this:EXEC sp_ExecuteSQL @MySQLParameter, N'@Param1 varchar(999), @Param2 int, ...', @Param1 = @Param1, @Param2 = @Param2, ...
you would need to, also, pass @Param1, @Param2, ... to your SProc (or declare and originate values for them there).sp_ExecuteSQL will avoid issues with SQL Injection, and its query plans will be reused - whereas with EXEC it is likely that every query will make a new query plan, which will NOT scale well and is likely to perform very badly on a database of any size.With sp_ExecuteSQL your @MySQLParameter would be something like:SELECT Col1, Col2, ...FROM MyTableWHERE Col1 = @Param1 AND COl2 = @Param2, ...
and NOT like thisSELECT Col1, Col2, ...FROM MyTableWHERE Col1 = 'FooBar' AND COl2 = 123, ...
because it is that parameterisation which allows the Query Optimiser to reused the cached query plan.