Dynamic SQL statements

Results 1 to 3 of 3

Thread: Dynamic SQL statements

  1. #1
    Tony H Guest

    Default Dynamic SQL statements

    I have an update statement with fields that will vary depending on what fields in the form the user has filled out. Is there a way to dynamically build the update without knowing beforehand what fields will be included? Can I read values into an array and pass those values as parameters and loop them into a stored procedure?<BR>Thanks for any input!

  2. #2
    Join Date
    Dec 1969

    Default RE: Dynamic SQL statements

    I can answer your first question, about dynamically building the update statement without knowing what fields will be updated...<BR><BR>Use something like this, but replace YourID and YourTable with the names of your ID field and your Table name. You can also use variables for these names, and build them dynamically as well.<BR><BR>FOR EACH name IN Request.Form<BR><BR> IF name INSTR(name, "YourID") &#060; 1 THEN <BR> MyVars=MyVars&name&"=&#039"&Request.Form(name)&"&# 039,"<BR> END IF<BR> NEXT<BR> <BR> MyVars = left(MyVars, len(MyVars)-1) &#039Get rid of trailing comma<BR> MyCols = "UPDATE YourTable SET "&MyVars&" "<BR> MyVals = "WHERE YourID = &#039"&Request.Form("YourID")&"&#039"<BR> MySQL = MyCols&MyVals<BR> DataConn.Execute MySQL<BR><BR>As far as looping them into a stored procedure, I would need to know exactly what you want that stored procedure to do...<BR><BR>Good Luck,<BR>-Ryan

  3. #3
    Tony Guest

    Default RE: Dynamic SQL statements

    I was thinking if I could somehow gather the parameters or fields for the update and then pass them to the stored procedure which would actually hold the update statement. I don&#039t know much about stored procedures, so I don&#039t really know if it will even work!<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