Thursday, March 22, 2012

accessing another database in a stored procedure

hi

i have stored procedure and i need to access another database in my stored procedure

I'm going to query a table which is located in another database

as you know it is impossible to use the USE database keyword in stored procedures

so what should I do?

thanks.

create myProc
as

select someStuff from otherDb.dbo.otherTable
.....

just qualify the table in the other db fully with the databasename.

/Kenneth

|||Not to mention permissions...the user executing the stored procedure should have permissions to the other database|||Hi

You specify a different database on the same sql server within a stored procedure using the format:
[databasename].dbo.TableName

for example

select [Users].dbo.Addresses

No comments:

Post a Comment