May 19, 2009 at 8:10 pm
when i insert a record into a table how do i capture server name and database name into that column?
May 19, 2009 at 8:23 pm
[font="Verdana"]For servername, use @@servername, and for database name, use db_name(). For example:
select@@servername,
db_name();
[/font]
May 19, 2009 at 8:31 pm
I am trying to do something like this
INSERT into OBBR.Emp.dbo.Revcounts
(col1,col2,dbname)
SELECT
col1,col2,server-db
FROM #temp
In the column dbname i would like to have server.dbname and i am doing this way...
(@@servername+db_name())
May 19, 2009 at 8:56 pm
Tara (5/19/2009)
I am trying to do something like thisINSERT into OBBR.Emp.dbo.Revcounts
(col1,col2,dbname)
SELECT
col1,col2,server-db
FROM #temp
In the column dbname i would like to have server.dbname and i am doing this way...
(@@servername+db_name())
[font="Verdana"]Something like (@@servername+','+db_name()) might be a bit better, so you can tell where the name of the server ends and the name of the database begins. Did you try it? Did it work?[/font]
May 19, 2009 at 9:06 pm
Hi,
before that try this,
use the default is easy option and common usage.
create table #temp
(
slno int,
DBNAME varchar(10) default db_name(),
servername varchar(15)default @@servername
)
insert into #temp (slno)
select 1
select * from #temp
ARUN SAS
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply