0
votes

Using Microsoft SQL Server 2015

This works

create procedure Checking1(@SQLQueryString nvarchar(max))
as
begin

select * from MyTable

end

This is not working

create procedure Checking1(@SQLQueryString nvarchar(max))
as
begin

@SQLQueryString

end;

What am I doing wrong?

1
Please move your suggestion as answer. I will mark it as answer. From your source I understand that I need to call it as like exec(@SQLQueryString). - Sixthsense
What value is the stored procedure providing here? - Martin Smith
This smells like an XY Problem. Passing a string to just execute is a HUGE security vulnerability. What controls do you have to stop a user running DROP TABLE dbo.MyTable or CREATE LOGIN a WITH PASSWORD = '1', CHECK_POLICY = OFF; ALTER SERVER ROLE sysadmin ADD MEMBER a;? - Larnu
Also there is no "Microsoft SQL Server 2015" - Charlieface

1 Answers