i got an apps that called stored procedure to get result. the input from the apps is like this:
- Group - nullable
- Name - nullable. if i fill Name, ID no need to be filled
- ID - nullable. if i fill ID, Name no need to be filled
- Segment - not nullable. the input can be ALL segment
- Period - not nullable
The "WHERE" possibilities that thinking of me is 12 possibilities.
- Segment, Period
- Segment, Period, ID
- Segment, Period, Name
- Segment, Period, Group
- Segment, Period, Group, ID
Segment, Period, Group , Name
ALL Segment, Period
- ALL Segment, Period, ID
- ALL Segment, Period, Name
- ALL Segment, Period, Group
- ALL Segment, Period, Group, ID
- ALL Segment, Period, Group, Name
and the example query is like this:
IF @Group IS NOT NULL AND @ID IS NOT NULL AND @Segment = 'KIDS'
BEGIN
SELECT * FROM mytable
WHERE Group = @Group AND ID = @ID AND Segment = @Segment
END
Is there any way to shorten the possibilities, so the query is less to be written?
Thank you