SQL optional parameters through VB.net
- by ScaryJones
I've a document search page with three listboxes that allow multiple selections. They're:
Category A
Year
Category B
Only category A is mandatory, the others are optional parameters and might be empty.
Each document can belong to multiple options in Category A and multiple options Category B but each document only has one year associated with it.
I've kind of got this working through building up a dynamic SQL string but it's messy and I hate using it so I thought I'd ask here if anyone could see an easier way of doing this. An example of the kind of dynamic SQL query i end up with follows:
select *
from library
where libraryID in
(select distinct libraryID from categoryAdocs where categoryAdocID in (4))
or year in (2004)