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.
| Author |
Topic |
|
schinni
Yak Posting Veteran
66 Posts |
Posted - 2004-01-16 : 09:57:46
|
| hello!Can i get the database names from the sql queryother than using thisSelect name from sysdatabasesAll i want to find out is if there is way of getting database nameother than using sysdatabases ..Thanks in advance, |
|
|
setbasedisthetruepath
Used SQL Salesman
992 Posts |
Posted - 2004-01-16 : 10:04:58
|
| If sysdatabases works for you, what's the reason for trying to find another way?JonathanGaming will never be the same |
 |
|
|
raymondpeacock
Constraint Violating Yak Guru
367 Posts |
Posted - 2004-01-16 : 10:33:52
|
| Try this:EXEC sp_MSForEachDb 'USE ? PRINT DB_NAME()'Raymond |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-01-16 : 12:35:17
|
| Sysdatabases is the way to go according to your brief question. But what you are trying to do?Tara |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2004-01-17 : 17:37:43
|
quote: Try this:EXEC sp_MSForEachDb 'USE ? PRINT DB_NAME()'
It's even easier than that:EXEC sp_MSForEachDb 'PRINT ''?'''Although I have to echo the question "Why not use sysdatabases?", it's the easiest and best method available. sp_MSForEachDB uses it anyway. |
 |
|
|
AjarnMark
SQL Slashing Gunting Master
3246 Posts |
Posted - 2004-01-18 : 18:41:17
|
| Did you just want the CURRENT database name? Then just use SELECT DB_NAME()--------------------------------------------------------------Find more words of wisdom at [url]http://weblogs.sqlteam.com/markc[/url] |
 |
|
|
ValterBorges
Master Smack Fu Yak Hacker
1429 Posts |
|
|
|
|
|