Using the Master database is there a way to return a value if a table exists in a different database.
Any help would be great.
Currently I am trying to get it this way.
DECLARE @vCharDatabaseName varchar(255)
SET @vCharDatabaseName = 'MyDatabase'
/* @vCharDatabaseName is passed into the SP */
DECLARE @TableName varchar(255)
SET @TableName = '[' + @vCharDatabaseName +'].[dbo].[DumpTable]'
If EXISTS(select * FROM SYSDATABASES, sysobjects WHERE SYSDATABASES.NAME =@vCharDatabaseName AND (sysobjects.id = object_id(@TableName))and OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
TRUNCATE table @TableName
Print 'TRUNCATE DumpTable'
END
Else
Print 'No Action Taken'
Any help would be great.
Currently I am trying to get it this way.
DECLARE @vCharDatabaseName varchar(255)
SET @vCharDatabaseName = 'MyDatabase'
/* @vCharDatabaseName is passed into the SP */
DECLARE @TableName varchar(255)
SET @TableName = '[' + @vCharDatabaseName +'].[dbo].[DumpTable]'
If EXISTS(select * FROM SYSDATABASES, sysobjects WHERE SYSDATABASES.NAME =@vCharDatabaseName AND (sysobjects.id = object_id(@TableName))and OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
TRUNCATE table @TableName
Print 'TRUNCATE DumpTable'
END
Else
Print 'No Action Taken'