Solved

SyBaseSQL Select column if it exists

Posted on 2014-04-06
3
1,441 Views
Last Modified: 2014-04-07
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
0
Comment
Question by:triphen
  • 2
3 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39982214
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.
0
 

Author Comment

by:triphen
ID: 39983804
I like the dynamic idea. How can I check if the column exists?
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 39984178
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Query still returning duplicates 5 41
Oracle Query - Convert letters to numbers and display the difference 3 30
TSQL Challenge... 7 36
sql server query 12 26
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question