how do i get the hostname in sql?

Posted on 2009-04-21
Last Modified: 2012-08-14
i've created a view on a db2 v9.1 on AIX
i need to extract the hostname in a variable, and use that variable in a query instead of hardcoding the hostname
how do i get the hostname (actual machine name) in sql?
select col1, 'MY_HARDCODED_HOST_NAME' as hostName, col2, etc

Open in new window

Question by:iamari
    LVL 9

    Expert Comment

    LVL 26

    Expert Comment

    The netnerds article is perhaps only partially correct. Apparently, what it's a solution for is the 'database name' rather than the hostname. Although those names are often the same, they're also often different. (The SQL0114 at the end of the article seems to reach the goal.)

    So, please clarify _exactly_ what name is being sought.

    A hostname would be useful for DNS resolution to an IP address. A database name would be useful for remote SQL requests.

    LVL 37

    Accepted Solution

    you can get it from a view called ENV_SYS_INFO  :
    select HOST_NAME    
    LVL 2

    Author Closing Comment

    thanks a lot, momi!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Recursive SQL in UDB/LUW (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
    Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now