开发者

How to pass database name into stored procedure?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜