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 {database}

Author  Topic 

Torch
Starting Member

20 Posts

Posted - 2005-07-11 : 20:37:10
Im unsure on the exact syntax of the "USE" command in SQL.

What I'm trying to do is run an SQL script that drops and creates tables in a different database (but on the same server). However I am getting the error:

Error 154: a USE database statement is not allowed in a procedure or trigger.

What Im doing is the following:

CREATE PROCEDURE [dbo].[dropTables]
@database varchar(200)
AS
USE @database
....

Any help in this matter would be much appreciated.

Torch.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-07-12 : 00:36:20
Instead of using Use, you can use DBname..tablename approach
CREATE PROCEDURE [dbo].[dropTables]
@database varchar(200)
AS
--Use Dynamic SQL to include DBName
Exec('Select columns from '+@database+'..tablename')


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Torch
Starting Member

20 Posts

Posted - 2005-07-12 : 05:08:45
Thanks, thats the approach I used in the end.

Torch.
Go to Top of Page
   

- Advertisement -