- Moderator
- #1
So I'm looking for a push in the right direction, short of building a HUGE dynamic query with a TON of IF statements.
Here's the scenario.
I'm doing an "Ad-hoc" report, based off of a couple of tables. Joining the tables is no big deal. It's call record data.
I have an input form, which will consist of a bunch of checkboxes and text fields.
For Example:
(Checkbox) Name (Textbox)
(Checkbox) City (Textbox)
So, if someone puts a check in the checkbox, it needs to select/show that field. If someone types into the textbox, it needs to filter by that field.
It could be any combination.... for example, it could be a checkbox in the name (show the names) no checkbox in the city, but a city name in the City textbox, meaning "I want to select Name where city = (textbox value)"
Needless to say, this will have a lot more checkboxes and fields than just two.
So, has someone done this? Like I said, I'd rather use some logic besides
If @chkName = true Then
@sql = @sql + ', Name'
End
If @txtName != '' Then
@sql = 'AND Name = ''' + @txtName + '''
End
... sort of stuff. I'm sure I'll end up having to concatenate a long SQL query and execing it... but is there a better way than brute force with if statements?
Just my 2ó
"What the captain doesn't realize is that we've secretly replaced his Dilithium Crystals with new Folger's Crystals."
--Greg
Here's the scenario.
I'm doing an "Ad-hoc" report, based off of a couple of tables. Joining the tables is no big deal. It's call record data.
I have an input form, which will consist of a bunch of checkboxes and text fields.
For Example:
(Checkbox) Name (Textbox)
(Checkbox) City (Textbox)
So, if someone puts a check in the checkbox, it needs to select/show that field. If someone types into the textbox, it needs to filter by that field.
It could be any combination.... for example, it could be a checkbox in the name (show the names) no checkbox in the city, but a city name in the City textbox, meaning "I want to select Name where city = (textbox value)"
Needless to say, this will have a lot more checkboxes and fields than just two.
So, has someone done this? Like I said, I'd rather use some logic besides
If @chkName = true Then
@sql = @sql + ', Name'
End
If @txtName != '' Then
@sql = 'AND Name = ''' + @txtName + '''
End
... sort of stuff. I'm sure I'll end up having to concatenate a long SQL query and execing it... but is there a better way than brute force with if statements?
Just my 2ó
"What the captain doesn't realize is that we've secretly replaced his Dilithium Crystals with new Folger's Crystals."
--Greg