Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass Database name as Stored Procedure Parameter 1

Status
Not open for further replies.

Appollo14

Technical User
Sep 4, 2003
182
0
0
GB
Hi,

I need to be able to set the database name used within a stored procedure by passing a parameter at run time. I know how to pass a parameter normally but I seem to be a bit stuck on this one.

Here is an illustration of how i thought it would work.

create procedure [dbo].[sp_Lock]
@dbExt varchar(10)
Update MyDb_ + @dbExt +.dbo.myTable
set myValue = 1
go

Unfortunately, it doesn't like the syntax that i put in.

Any Ideas?

Regards,
Noel.
 
I'm pretty sure you have to use the exec() command when building a query out of a string.

[monkey][snake] <.
 
sorry, syntax:

Code:
exec('Update MyDb_' + @dbExt + '.dbo.myTable set myValue = 1')

[monkey][snake] <.
 
Hi Monksnake,

thanks for the reply. I had'nt even thought of that approach, i thought that i'd just be able to add the parameter and that sql would just concatenate the fields.

Many thanks,
Noel.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top