Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Expert


Need a universal statement which can perform this


MASTER
-------
IDNO NAME GENDER EDUCATION
--------------------------------------
001 JAMES MALE HIGH SCHOOL
002 JOHN MALE UNIVERSITY
003 AMY FEMALE HIGH SCHOOL
004 PAT FEMALE UNIVERSITY
005 ANN FEMALE HIGH SCHOOL



GENDER can be 'ALL/MALE/FEMALE'

EDUCATION can be 'ALL/HIGH SCHOOL/UNIVERSITY'


Need a general purpose Select statement as follows


Select * from MASTER WHERE GENDER='' AND EDUCATION=''


How do you handle a generIc Select statement to handle

'ALL' for GENDER in addition to 'MALE/FEMALE'

'ALL' for EDUCATION in addition to 'HIGH SCHOOL/UNIVERSITY'

Please assist

What I have tried:

This is what I have tried . please assit
Posted
Updated 12-Oct-17 5:33am
v2

1 solution

For generic statements where you want "any of them", just exclude it from the WHERE clause:
SQL
SELECT * FROM Master WHERE Education='UNIVERSITY'
Will return any gender. Similarly,
SQL
SELECT * FROM Master WHERE Gender='MALE'
Will return any education status.

But that's a very poor DB design: there is a huge amount of duplication. You shoudlk consider setting up separate Gender and Education tables:
Gender
Id     INT, IDENTITY, PRIMARY KEY
Desc   NVARCHAR

Education
Id     INT, IDENTITY, PRIMARY KEY
Desc   NVARCHAR
You then use a foreign key to each ID field in your main table instead of storing the description so many times, and use JOINs to "combine" the tabels for output as necessary.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900