SQL optional parameters through VB.net
Posted
by ScaryJones
on Stack Overflow
See other posts from Stack Overflow
or by ScaryJones
Published on 2010-04-06T11:00:30Z
Indexed on
2010/04/06
11:03 UTC
Read the original article
Hit count: 286
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)
© Stack Overflow or respective owner