This is the second time I've searched on this and came up not fully understanding why this isn't possible. Say you have one text box, but you want to be able for a user to search by "company name," "job number," or "Order No," So you put one text box and a drop down list where the user can select what field to search.
Here is what I would like to do Select [order_no], [job_no], [company_name] From [order_tbl] WHERE @var1 Like '*@var2*' (maybe not totally correct syntax, but you get the picture....and @var1 is set from the selection of the dropdownlist and @var2 is set from the text box).
What I do now is three separate SQL statements. If DropDownlist1.SelectedValue = 1 then do, if it = 2 then do, etc.
But when you have a large select statement with table joins, you have to make any changes three times, and it seems easy to make a mistake...not to mention if you have more than three choices, you have an SQL statement for each choice.
Am I misunderstanding that it isn't possible to do a variable field name so I can have one select statement to work with? And if it isn't possible, I just wish I could wrap my head around why, because it seems such a simple thing to do.
View Complete Post