Insert

  • when i insert a record into a table how do i capture server name and database name into that column?

  • [font="Verdana"]For servername, use @@servername, and for database name, use db_name(). For example:

    select@@servername,

    db_name();

    [/font]

  • 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())

  • Tara (5/19/2009)


    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())

    [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]

  • 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