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 2005 Forums
 Transact-SQL (2005)
 get database name from record

Author  Topic 

Haz
Starting Member

38 Posts

Posted - 2009-01-08 : 02:10:04
Hi there,
does anyone know how to get database name
For example:
DBName CustNo CustName
db1 Cust1 CustA
db1 Cust2 CustB
db2 Cust1 CustA
db2 Cust2 CustB
db3 Cust1 CustA

i already try
SELECT DB_NAME() AS [Current Database];
but they display the same db name..
anyone has idea how get it?
Thanks..

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-01-08 : 02:20:44
I don't understand your question. What value do you want to return?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

ashishashish
Constraint Violating Yak Guru

408 Posts

Posted - 2009-01-08 : 02:35:10
Wat U want to ask ........
Specify which database name u want to get in your results?

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-08 : 02:36:26
do you mean you need to display all db's data from your server along with dbname?
Go to Top of Page

Haz
Starting Member

38 Posts

Posted - 2009-01-08 : 02:41:50
can all of u go to this link...
maybe u will understand what i try to tell u..sorry make u confius..

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=115552
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-08 : 02:46:08
[code]SELECT 'db1' AS DBName,field FROM db1..table
UNION ALL
SELECT 'db2',field FROM db2..table
UNION ALL
SELECT 'db3',field FROM db3..table
[/code]
Go to Top of Page
   

- Advertisement -