If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Column names via odbc

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-24-10, 21:10
curtmorehouse curtmorehouse is offline
Registered User
 
Join Date: Sep 2008
Posts: 27
Column names via odbc

can someone please help me construct an sql statement to retrieve just the column names for a specific table? The examples i've found so far don't work.

thanks!
Reply With Quote
  #2 (permalink)  
Old 06-24-10, 22:19
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
The informaiton is in syscat.columns. It is fairly straight forward. The DB2 catalog views are documented in the SQL Reference Vol 1, (appendicies).
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 06-25-10, 17:44
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Wink

Quote:
Originally Posted by curtmorehouse View Post
can someone please help me construct an sql statement to retrieve just the column names for a specific table? The examples i've found so far don't work.

thanks!
DB2 V8 z/os

select name
from sysibm.syscolumns
where tbname = ucase('Your_table_name_not_qlfd')


For example:

Code:
select name as ".......NAME.........." from sysibm.syscolumns
where tbname = ucase('SUB_RED_HY')
order by 1
Result:

.......NAME..........
ACT_CD
ACT_ALT
ACT_BRN_CD
SECURITY_ID
Reply With Quote
  #4 (permalink)  
Old 06-27-10, 14:13
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
That's a typical exercise in a class. So have a look at the DB2 catalog tables, and you should be able to handle it from there by yourself.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #5 (permalink)  
Old 06-28-10, 09:09
curtmorehouse curtmorehouse is offline
Registered User
 
Join Date: Sep 2008
Posts: 27
solved

None of the examples given worked for me, maybe I have an older OS?
Anyway, I did get it to work using PHP, and the code is below for anyone looking to retrieve column names via php with os/400...

Code:
	//SQL quyery  
$Query = "SELECT * from iesfile.drivers";

//execute query 
$queryexe = odbc_do($connectionstring, $Query);

 //query database
while(odbc_fetch_row($queryexe)) 
    {
    	
    //collect results 
    
    $numfields = odbc_num_fields($queryexe);
    
      for($i = 1;$i <= odbc_num_fields($queryexe);$i++)
    {
        $odbc['rows']['fieldnames'][$i] = odbc_field_name($queryexe,$i);
        $odbc['rows']['fieldtypes'][$i] = odbc_field_type($queryexe,$i);
        $odbc['rows']['fieldlengths'][$i] = odbc_field_len($queryexe,$i);
    }
    unset($i);
        
          }
Reply With Quote
  #6 (permalink)  
Old 06-28-10, 09:56
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Question Is it DB2

Quote:
Originally Posted by curtmorehouse View Post
None of the examples given worked for me, maybe I have an older OS?
Anyway, I did get it to work using PHP, and the code is below for anyone looking to retrieve column names via php with os/400...

Code:
	//SQL quyery  
$Query = "SELECT * from iesfile.drivers";

//execute query 
$queryexe = odbc_do($connectionstring, $Query);

 //query database
while(odbc_fetch_row($queryexe)) 
    {
    	
    //collect results 
    
    $numfields = odbc_num_fields($queryexe);
    
      for($i = 1;$i <= odbc_num_fields($queryexe);$i++)
    {
        $odbc['rows']['fieldnames'][$i] = odbc_field_name($queryexe,$i);
        $odbc['rows']['fieldtypes'][$i] = odbc_field_type($queryexe,$i);
        $odbc['rows']['fieldlengths'][$i] = odbc_field_len($queryexe,$i);
    }
    unset($i);
        
          }
Maybe it is not a DB2 at all ?

Lenny
Reply With Quote
  #7 (permalink)  
Old 06-28-10, 10:08
curtmorehouse curtmorehouse is offline
Registered User
 
Join Date: Sep 2008
Posts: 27
i think it is

I think it is DB2. The data I am querying resides on an AS/400 V5R3.
I am using PHP via a Win2K server to access the data via the Client Access ODBC driver.
Reply With Quote
  #8 (permalink)  
Old 06-28-10, 10:28
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Arrow

Quote:
Originally Posted by curtmorehouse View Post
I think it is DB2. The data I am querying resides on an AS/400 V5R3.
I am using PHP via a Win2K server to access the data via the Client Access ODBC driver.
You can find a lot here:

http://publib.boulder.ibm.com/infoce...v5r3/index.jsp

Lenny
Reply With Quote
Reply

Tags
column names, odbc

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On