February 5, 2007 at 9:17 pm
How can I do this?
IF DATABASE MyDataBase EXISTS
SELECT * FROM MyDataBase..MyTable
END
February 5, 2007 at 10:08 pm
Hi
If Exists (SELECT name from sysdatabases where name = 'MyDataBase')
BEGIN
USE MyDataBase
select * from MyDataBase..MyTable
END
"Keep Trying"
February 6, 2007 at 1:56 am
That's still going to give an error, from the parsing of the USE statement
Could not locate entry in sysdatabases for database 'MyDB'. No entry found with that name. Make sure that the name is entered correctly.
If you remove the use statement however, it works
If
Exists (SELECT name from sysdatabases where name = 'MyDB')
begin
select * from MyDB..sysobjects
end
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply