Link to home
Start Free TrialLog in
Avatar of triphen
triphen

asked on

SyBaseSQL Select column if it exists

Hello Experts,

I am using SyBase SQL Anywhere v10. My databases I select from may vary from version to version on my application. How can I select a column only if it exists in the table, else return 'Nothing Found'. X, Y and Z exist for sure, but A column A may not exist.

Something like....
SELECT
x,
y,
z,
CASE WHEN IF EXISTS column A
ELSE 'nothing found'
FROM TABLE 1234567
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

this does not exist in any dbms I know of ...

the only workaround I can suggest is to use views (or stored procedures), which would do the same ...
alternatively I only see dynamic sql: a query which checks if the column is there, and build the query as needed.
Avatar of triphen
triphen

ASKER

I like the dynamic idea. How can I check if the column exists?
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial