473,406 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Queries: How do I select only the columns that have values?

Hi All,

I am using Access 2003 and I want to show in my query all columns from a table that have values. Its probably a simple question but I have not been able to crack it so far.

My code is below, but it won't give me any of my columns.

SELECT IIf([Data table].[ID]= Not Null,"[Data table].[ID]) AS ID",IIf([Data table].[Attribute 1]= Not Null,"[Data table].[Attribute 1] AS Attribute_1",""))
FROM [Data table];

Thanks a lot!

Remaniak
Dec 6 '06 #1
8 4014
MMcCarthy
14,534 Expert Mod 8TB
Try this ...

Expand|Select|Wrap|Line Numbers
  1. SELECT [ID], [Attribute 1]
  2. FROM [Data table]
  3. WHERE [ID] Is Not Null
  4. AND [Attribute 1] Is Not Null;
  5.  
Dec 6 '06 #2
Try this ...

Expand|Select|Wrap|Line Numbers
  1. SELECT [ID], [Attribute 1]
  2. FROM [Data table]
  3. WHERE [ID] Is Not Null
  4. AND [Attribute 1] Is Not Null;
  5.  
Hi McCarthy,

Thanks for your reply, but this will only give me all rows where Attribute and ID are both empty. But I want the query to skip the column if all of its rows are empty.

Would that be possible as well?
Dec 6 '06 #3
NeoPa
32,556 Expert Mod 16PB
No I'm afraid not.
There is no facility in SQL to determine columns dynamically.
Dec 6 '06 #4
MMcCarthy
14,534 Expert Mod 8TB
Hi McCarthy,

Thanks for your reply, but this will only give me all rows where Attribute and ID are both empty. But I want the query to skip the column if all of its rows are empty.

Would that be possible as well?
This should be returning records where neither column is empty.

Mary
Dec 7 '06 #5
This should be returning records where neither column is empty.

Mary
Hi Mary,

You were right, it returns everthing where both column are not empty.

But there are no ways of constructing a piece of VBA code to build such a query?
Dec 7 '06 #6
MMcCarthy
14,534 Expert Mod 8TB
Hi Mary,

You were right, it returns everthing where both column are not empty.

But there are no ways of constructing a piece of VBA code to build such a query?
Remaniak

What exactly do you want your query to return and where do you want the returned records displayed.

Mary
Dec 7 '06 #7
Remaniak

What exactly do you want your query to return and where do you want the returned records displayed.

Mary
I want the query to return my table with only the columns that have values in them. (some have a header but no values)
From that query I will then make an export.
Dec 7 '06 #8
MMcCarthy
14,534 Expert Mod 8TB
I want the query to return my table with only the columns that have values in them. (some have a header but no values)
From that query I will then make an export.
Even if you built that kind of code which would be very complicated you would then have a report based on the results. For example there may be 5 columns. What happens if the next time there are 6 columns. Your report only has 5. Doing what you are suggesting is extremely complicated and in all honesty I'm not sure how it would work.

If you change the AND in the select statement I gave you previously to an OR it will at least only return those records where at least one of the columns has a value.

Mary
Dec 7 '06 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Florian | last post by:
Hi, I have a table that contains log data, usually around a million records. The table has about 10 columns with various attributes of the logged data, nothing special. We're using SQL Server...
1
by: gary b | last post by:
Hello When I use a PreparedStatement (in jdbc) with the following query: SELECT store_groups_id FROM store_groups WHERE store_groups_id IS NOT NULL AND type = ? ORDER BY group_name
7
by: mark.a.lemoine | last post by:
Our application currently interfaces to SQL Server and Oracle, we're implementing it into DB2 currently and I have a question to ask. First a little background - We're interfacing into DB2 v8 on...
0
by: mark.a.lemoine | last post by:
Our application currently interfaces to SQL Server and Oracle, we're implementing it into DB2 currently and I have a question to ask. First a little background - We're interfacing into DB2 v8 on...
4
MMcCarthy
by: MMcCarthy | last post by:
To view Access queries in SQL rather than Access query design - open the query design window and change the view to SQL: Select Statement SELECT FROM ; Append Statement INSERT INTO (, , )...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.