Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Stored Procedure with varchar(max) as parameter Expand / Collapse
Author
Message
Posted Tuesday, May 25, 2010 8:11 AM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Thursday, October 23, 2014 2:26 PM
Points: 752, Visits: 1,071
Hi,

I have this stored procedure:

create proc ExecuteScripts (@SQLstat varchar(max))
as
begin
exec SQLstat
end



When i try to create this procedure i receive the following warning from SQL Server:

Cannot add rows to sys.sql_dependencies for the stored procedure because it depends on the missing table 'SQLstat'. The stored procedure will still be created; however, it cannot be successfully executed until the table exists.



But SQLstat is a variable that i want to pass, not a table...

Can someone explain?

Thank you
Post #927496
Posted Tuesday, May 25, 2010 8:58 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, July 18, 2014 9:23 AM
Points: 43, Visits: 227
Assuming that you are passing the script to be executed in @SQLStat parameter, your procedure should be:

create proc ExecuteScripts (@SQLstat varchar(max))
as
begin
exec ( @SQLstat )
end

Also check sp_executesql if you need to use dynamic sql.

Neepa
Post #927544
Posted Tuesday, May 25, 2010 9:03 AM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Thursday, October 23, 2014 2:26 PM
Points: 752, Visits: 1,071
thank you.
Post #927555
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse