Passing a variable to define a column

Results 1 to 2 of 2

Thread: Passing a variable to define a column

  1. #1
    pmorales Guest

    Default Passing a variable to define a column

    I can&#039;t get this select statement to work. It won&#039;t see the variable strcolumn for some reason. I know that the select statement works because if I enter a column name in place of strcolumn it works fine.<BR><BR>&#060;%strname=request.form("name1")% &#062;<BR>&#060;%strcolumn=request.form("column")% &#062;<BR><BR>All="select * from admin, requestor, newprojects, bugfix where<BR> and and<BR> and &#039;" & strcolumn & "&#039;=&#039;"& strname &"&#039;"

  2. #2
    Join Date
    Dec 1969

    Default RE: Passing a variable to define a column

    If you would do <BR><BR>&#060;%<BR>...<BR>Response.Write "SQL is " & All & "&#060;HR&#062;"<BR>...<BR>%&#062;<BR><BR>You would see that your query ends with something like<BR><BR> and &#039;columnXYZ&#039;=&#039;zamboni&#039;<BR><BR>N ow, tell me something: Do you see any &#039;...&#039; marks around the names of the fields in the *rest* of your query? Or in any other query? Nope.<BR><BR>So you just asked SQL to test if the STRING columnXYZ is the same as the STRING zamboni. And of course they aren&#039;t the same, so that part of the WHERE is false so the entire WHERE is false so you get no results.<BR><BR>The obvious answer is to get rid of the &#039;...&#039; around the strcolumn. But will that be enough???? What happens if the user chooses a column that is *NUMERIC* instead of a text column? Or one that is a DATE field???<BR><BR>Can you say "oops"?<BR><BR>I *must* go home now. Think about it a while!<BR><BR>HINT: From the form, have strcolumn return not *just* the column name but a prefix character that indicates what kind of field it is in the DB and generate SQL appropriate to that kind of field.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts