473,473 Members | 2,144 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Is a where clause possible in show columns command?

10 New Member
Hi,

I want to return specific column titles based on a certain condition from the column's values:
E.g

in the table Employees:

Expand|Select|Wrap|Line Numbers
  1. EmployeeID  Monday   Tuesday   Wednesday
  2.     1          1         0       0
  3.     2          0         1       1
  4.  
The type of the days is BOOLEAN -- one represents present,
zero absent,
I want using the show columns to return the days that employeeID 2 is absent, so something to this effect.

Expand|Select|Wrap|Line Numbers
  1. show columns from Employees where EmployeeID = 2 
  2.  
  3. && Monday = 0 && Tuesday =0 && Wednesday = 0
  4.  
  5.  
Above does not work,
but what would using show columns or not?

and in the query how can use a wildcard instead of having to repeat Monday , Tuesday, Wednesday?


Any help on the logic of this query would be appreciated.
Thanks.
Feb 17 '11 #1
3 2436
Rabbit
12,516 Recognized Expert Moderator MVP
Aside from the poor table design, I have no idea what results you're looking for. It sounds like you need to unpivot your data before you do your query. But that's a guess since I don't know the results you're expecting.
Feb 17 '11 #2
JKing
1,206 Recognized Expert Top Contributor
With the data you provided your query would never return anything as there is no row where all columns equal zero.

As rabbit has said this is poor table design. You should separate your data. Make one table for employees and their information like name, address etc.
Make another table for attendance. This table could use the date + employeeID as the primary key with an additional column for present/absent.
Feb 17 '11 #3
dgreenhouse
250 Recognized Expert Contributor
Expand|Select|Wrap|Line Numbers
  1. SELECT employeeid,
  2. CONCAT((CASE WHEN monday = 0 THEN 'Monday, ' ELSE '' END),
  3. (CASE WHEN tuesday = 0 THEN 'Tuesday, ' ELSE '' END),
  4. (CASE WHEN wednesday = 0 THEN 'Wednesday, ' ELSE '' END),
  5. (CASE WHEN thursday = 0 THEN 'Thursday, ' ELSE '' END),
  6. (CASE WHEN friday = 0 THEN 'Friday, ' ELSE '' END)) AS days_absent
  7. FROM employees WHERE monday=0 OR tuesday=0 OR wednesday=0 OR thursday=0 OR friday=0
  8.  
I'll leave it up to you to figure out how to strip off the trailing comma.
Feb 28 '11 #4

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

Similar topics

2
by: steve | last post by:
To gain performance, do I need to index ALL the fields in the where clause. Say we have a query like: select stuff from table where field1=.. and field2=... If field1 selection substantially...
1
by: msnews.microsoft.com | last post by:
Hi All, When I use a SQL Query to Fill the Dataset if I use the following Where Clause ( > '100' ) Then I am getting a 'Data Type Mismatch Error' because the Field Type is double.
2
by: Zygo Blaxell | last post by:
I have a table with a few million rows of temperature data keyed by timestamp. I want to group these rows by timestamp intervals (e.g. every 32 seconds), compute aggregate functions on the...
0
by: jobs | last post by:
I have a gridview that times when selecting from specific table when I try to when I add a where clause. Even when I'm only seleting Top 1 which comes right back at the command line. I test the...
2
by: Jim.Mueksch | last post by:
I am having a problem with using calculated values in a WHERE clause. My query is below. DB2 gives me this error message: Error: SQL0206N "APPRAISAL_LESS_PRICE" is not valid in the context where...
5
by: pwiegers | last post by:
Hi, I'm trying to use the result of a conditional statement in a where clause, but i'm getting 1)nowhere 2) desperate :-) The query is simple: -------- SELECT idUser,...
14
by: keri | last post by:
Hi, Simple version of the question..... How do I use the where clause of the open form command to show an account with a matching ID to be displayed when the form is opened? Eg. I select a...
2
by: =?Utf-8?B?Qm9iQWNoZ2lsbA==?= | last post by:
Is there a resource limit on how many items can be put in the Where clause of a select command that retrieves rows to a OleDbDataAdapter dataset? Can it be unlimited if I change some settings? ...
2
by: Dan | last post by:
Hello, all! New here, so please forgive if this has been answered before. I use MySQL most often, and can use the commands: show tables in ; show columns in ; which lists all the tables in...
4
by: Bernard Dhooghe | last post by:
Table definition: CREATE TABLE "SCHEMA1 "."X2" ( "C1" CHAR(20) NOT NULL , "C2" CHAR(10) NOT NULL , "C3" CHAR(30) NOT NULL GENERATED ALWAYS AS (C1|| C2) ) IN "USERSPACE1" ; -- DDL...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
1
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.