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
 General SQL Server Forums
 New to SQL Server Programming
 listing database name

Author  Topic 

rudba
Constraint Violating Yak Guru

415 Posts

Posted - 2009-04-24 : 14:14:03
I would like to list the database name from system databases and check in my TestDb's tblDbName, i do not get the list even there are matching records.

Can you find out what is the wrong here?


select a.[name] from sys.databases a, TestDb.dbo.[tblDbName] b
where (a.[name]=b.[db_Name]) AND b.db_Status=1)) AND (a.[name] in('MyDb','master','model','msdb'))

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-04-24 : 14:40:34
Including (a.[name] in('MyDb','master','model','msdb')) would list you only one of these provided you have them in TestDb.dbo.[tblDbName]
Go to Top of Page

rudba
Constraint Violating Yak Guru

415 Posts

Posted - 2009-04-24 : 14:46:53
i have list of database name on tblDbName (not in all database names like sys.databases) and i don't have some database name on tblDbName (MyDb,master,model,msdb) so i would like to list the all database names from tblDbName plus MyDb,Master,Model,Msdb too
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-04-24 : 14:52:36
[code]select
a.[name]
from
sys.databases a join TestDb.dbo.[tblDbName] b
on
a.[name]=b.[db_Name] AND b.db_Status=1
UNION
select 'MyDb'
UNION
select 'master'
UNION
select'model'
UNION
select 'msdb'[/code]
Go to Top of Page

rudba
Constraint Violating Yak Guru

415 Posts

Posted - 2009-04-24 : 15:05:28
thanks, perfect job
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-04-24 : 16:43:57
np
Go to Top of Page
   

- Advertisement -