Search code examples
c#sqlaliasibm-midrange

Alias containing space in SQL using AS400 database


I have an SQL statement and I would like to have an alias with a space. For example:

SELECT item as Alternate Item from Items;

I tried different syntaxes but it fails.

SELECT item as "Alternate Item" from Items;
SELECT item as [Alternate Item] from Items;
SELECT item as {Alternate Item} from Items;

It works fine if I change the alias to Alternate for example which doesn't contain spaces.

I am running the sql using the following code:

DataSet dataset = new DataSet();
OdbcCommand command = new OdbcCommand(sql);
command.Connection = con.Connection;
OdbcDataAdapter adapter = new OdbcDataAdapter(command);
con.Open();
adapter.Fill(dataset); // At this line I get the following error

An unhandled exception of type 'System.Data.Odbc.OdbcException' occurred in System.Data.dll

The database is AS400.


Solution

  • What version of IBM i?

    This works fine on 7.1

    SELECT IBMREQD as "alt name" FROM sysibm.sysdummy1