Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2003
    Posts
    1

    Unanswered: Host_name() returns empty value

    the host_name() function returns an empty value when it runs from a trigger. when I run the same update statement from query analyzer or set a value to trigger the trigger, the correct hostname is returned.

    Here is what we did:

    1) Setup a field called hostname, nchar, 20
    2) Created a user defined function called hostname.

    CREATE function HostName ()
    returns nchar(20)
    as begin
    return Right(host_name(),20)
    end

    3) Modified our trigger to include the function.
    ...
    update hr_active_table
    set Issuedby = dbo.username(), hostname = dbo.hostname(),
    ...

    once that returned blanks, I modified the trigger to bypass the user defined function of hostname

    ...
    update hr_active_table
    set Issuedby = dbo.username(), hostname = host_name(),
    ...

    this also returns a blank field.

    anyone know how to correct this?

    thanks,
    jennifer

  2. #2
    Join Date
    Jul 2002
    Location
    Village, MD
    Posts
    621

    Re: Host_name() returns empty value

    This works fine on my computer - try on yours:

    create table testtable(id int,code varchar(10))
    go
    alter trigger inserttable on testtable
    for insert
    as
    select right(HOST_NAME(),20)
    go
    insert testtable select 1,'1'
    go
    --------------------
    MYHOST

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •