www.webdeveloper.com
Results 1 to 3 of 3

Thread: Selecting dynaminc fields in an SQL statement

  1. #1
    Join Date
    Oct 2005
    Posts
    32

    Question Selecting dynaminc fields in an SQL statement

    Hi,

    I have a one record table, part of which consists of three fields which store image names.

    menu_image_1, menu_image_2 and menu_image_3

    To delete either of these images from the record, I am attempting to use the script below. The querystring "image" contains the field name of the appropriate image, and I am trying to dynamically insert it into the Query, but it keeps giving me a syntax error message:

    <%

    Dim empty_value
    empty_value = null

    Set rs_deleteimage = Server.CreateObject("ADODB.Recordset")
    rs_deleteimage.ActiveConnection = MM_conn_db_STRING

    rs_deleteimage.Source = "UPDATE tbl_menu SET ' " & request.querystring("image") & " ' = '" & empty_value
    rs_deleteimage.CursorType = 0
    rs_deleteimage.CursorLocation = 2
    rs_deleteimage.LockType = 1
    rs_deleteimage.Open()

    response.Redirect("../control/menu_admin.asp")

    rs_deleteimage.Close()
    Set rs_deleteimage = Nothing
    %>


    What is the correct syntax for including this querystring in the query?

    Thanks,

    Adam

  2. #2
    Join Date
    Nov 2005
    Posts
    47
    The line:
    rs_deleteimage.Source = "UPDATE tbl_menu SET ' " & request.querystring("image") & " ' = '" & empty_value

    should read:
    rs_deleteimage.Source = "UPDATE tbl_menu SET " & request.querystring("image") & " = '" & empty_value & "'"

    If "image" is the name of the field then you can't have quotes around it. Also you don't have a closing quote for the empty_value variable.

  3. #3
    Join Date
    Oct 2005
    Posts
    32
    Thanks,

    That worked a treat. I had tried it without the quotation marks, so it must've been the one missing at the end that caused it.

    But I had used that empty_value item in another query, with static values, without quotation marks at the end and it had worked. Strange.

    Anyway, thanks again,

    Adam

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles