How to pass database name into stored procedure? I tried something like
create procedure dbo.Test
@databaseName varchar(100)
as
select * from @databasename开发者_如何学JAVA.Person.Address
go
I would like to use it like this
execute dbo.Test @databaseName = 'AdventureWorks'
This is not possible in the manner you are describing.
You can do this with dynamic SQL, but that brings its own set of problems.
Sounds like you are trying to move information which should be part of connection string into stored procedure logic. If you expect that Person table will be in different database this database name should be fixed in deployment - for example by parametrized creation script and sqlcmd.
精彩评论