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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 "USE " Inside stored procedure

Author  Topic 

rajesha
Starting Member

36 Posts

Posted - 2003-03-28 : 03:44:46
How can i use the USE inside a stored proc.
i want to change the dbname using the use command inside a sp.how can do that
exec 'USE'+@dbnname()
is not working can anyone help me...

nr
SQLTeam MVY

12543 Posts

Posted - 2003-03-28 : 05:25:09
You can't.
A stored procedure is an object in a database and therefore operates within that context.
You can access objects in another database by qualifying the name

dbmane.owner.objectname.

You can execute a statement within the context of another database by

exec dbname..sp_executesql N'sql statement'

Note that for all cross database operations permissions will be checked for the login.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -