Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to pass the file path to a proc

Author  Topic 

MGA
Starting Member

28 Posts

Posted - 2010-05-25 : 12:10:58
i have the following proc that attach a database with the mdf and log files the question is how to replace the file path 'c:\R_Data.mdf' and 'c:\R_log.ldf' with the passed parameters @mdffile and @logfile pathes

create proc attachdatabase(@mdffile varchar(60),@logfile varchar(50))
as
begin
CREATE DATABASE MyAdventureWorks
ON (FILENAME = 'C:\R_Data.mdf'),
(FILENAME = 'C:\R_Log.ldf')
FOR ATTACH
end
go

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-05-25 : 12:24:48
One way is use the dynamic sql:

You can use "Exec" command or Sp_executeSQL command but please check the below article for more detailed info and issues with dynamic sql.

http://www.sommarskog.se/dynamic_sql.html

Regards,
Bohra

I am here to learn from Masters and help new bees in learning.
Go to Top of Page
   

- Advertisement -