informix - SQL IF/CONDITIONAL Querty -
is possible structure query display static value row based on column?
eg.
in informix, syscolumns type returned integer. have print out table type string rather integer.
for example, when run simple query system tables
select * syscolumns tabid < 100
i get
colname tabid colno coltype collength ------------------------------------------------ tabname 1 1 13 128
where coltype = 13 corresponds varchar
so original query give me
colname coltype col1 0 col2 1 ...
but want returned as
colname coltype col1 char col2 smallint ...
is such thing possible in single query?
select column, case when coltype = 0 'char' when coltype = 1 'smallint' else cast(coltype varchar) end coltype mytable
so, example, table:
column | coltype -------------+-------------- col1 | 0 col2 | 1 col3 | 2
the result be:
column | coltype -------------+-------------- col1 | char col2 | smallint col3 | 2
however, if coltype
maps id
or similar in table, make more sense join table, like:
select mytable.column, secondtable.columnname mytable join secondtable on mytable.coltype = secondtable.coltype
Comments
Post a Comment