Click here to Skip to main content
13,193,650 members (57,847 online)
Rate this:
 
Please Sign up or sign in to vote.
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 12-Oct-17 5:09am
Updated 12-Oct-17 5:33am
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

For generic statements where you want "any of them", just exclude it from the WHERE clause:
SELECT * FROM Master WHERE Education='UNIVERSITY'
Will return any gender. Similarly,
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.
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web02 | 2.8.171018.2 | Last Updated 12 Oct 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100