Hey All,
First time poster, looking for some ideas or guidance with a small project I currently have.
I have slowly been ramping up on my db2 skills using online sites and now i hope this site can help..
Basically what I need is a stored procedure that is sent multiple parameters. I need to query tables based on these parameters. It would be pretty simple except I cannot expect all parameters to be populated on every call.
For example lets say the screen has first name, last name, employee number and department. I need to pull records off a table based on this. If they pass all 4 parms at all times it becomes a simple select and I'm done..
BUT the issue is I can be passed just a first name, or a last name and nothing else. Any combination really, the less parameters the more rows I would return. If someone passes first name last name and employee number I would grab 1 record, if they pass just last name I can grab all "smiths"...
So, I am not sure if there is such a concept of dynamic clauses, where if I want the AND statement executed I can put it in an if statement of some sort... I can ask for "-1" if a parameter is not chosem..
So..
(Psuedo code/english?)
select ****
where 1=1
(if vfname != -1) AND fname = vfname
(if vlname!= -1) AND lname = vlname
(if vemp!= -1) AND emp = vemp
(if vdep!= -1) AND dep = vdep
If all parms are -1 I would just return the entire table...
I've been working with DB2 for just a little bit so I doubt something like this is out there so this is why I come here for ideas....
I hope all this made sense, I'll provide more detail is needed
