Hyphen as column name in database

Asked

Viewed 154 times

1

It is possible to work with hyphenated columns (-) within a select?

Example: SELECT fm-codigo, descricao FROM ems2cad.pub.familia

Progress database

I am performing the query using PHP via ODBC, already tried several means, how to use crase, simple quotes, brackets, keys but none solves, the results I get are errors saying that the column was not identified or no value returned.

Code used for testing below:

<html>
    <head>
        <title>Teste de relatórios</title>
    </head>
    <body>  
        <?php
            $connect = odbc_connect('ems2cad', *user*, *pass*);
            $sql = "SELECT fm-codigo, descricao FROM ems2cad.pub.familia";
            $result = odbc_exec($connect , $sql);
        ?>

        <table width=”600” height=”500”>
            <tr>
                <td>fm-codigo</td>
                <td>descricao</td>
            </tr>  

            <?php
                while (odbc_fetch_row($result)) {
            ?>
            <tr>
                <td><?php echo odbc_result($result, 'fm-codigo');?></td>
                <td><?php echo odbc_result($result, 'descricao');?></td>
            </tr>       
            <?php     
                }
                odbc_close($connect);
            ?>
        </table> 
    </body>
</html>
  • It should work. Make sure you get data without using one of these fields, just as a test. My guess is that you’re not really connecting to the bank (am I an SQL connection for you? Can you get data from any table?).

  • @bupereira I can bring the information if I use select all, so yes, I am connected to the bank, however to treat these fields that have hyphenate in joins and clauses Where I need to be able to call them and that is where my difficulty lies. Another example, in this same code, if I let select so SELECT 'fm-codigo', Description, it returns me two columns, one repeating the values 'fm-codigo' and another bringing the values of the description that are in the database

1 answer

0


First of all thanks to all who are willing to help.

I contacted a support in which I was given the following tip:

In this case the "fm-code" of your example should arrive in the database Progress with Dual Apas, but now you need to adapt your string to send these quotes together.

Thus the final result was:

$sql = 'SELECT "fm-codigo", descricao FROM ems2cad.pub.familia';

Simple but costly solution. Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.