Results 1 to 4 of 4

Thread: form

  1. #1
    Kate Guest

    Default form

    I am creating a dynamic form from DB...when I am doing a search ... I am building my sql from these fields ... how can I make my sql like this ...<BR><BR>select * from tablename where filed1 AND field2 AND field3 <BR> <BR>right now it is putting "AND" after field3 how can I get rid of this "AND" after the last value in the where clause... any ideas....<BR>Thanks for help<BR><BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default See also 'looping problem' below!

    EXACTLY the same question!<BR><BR>The trick is easy:<BR><BR>Instead of putting "AND" on the end of each term, put it on the beginning:<BR><BR>where = where & " AND " & fieldname & "=" & value<BR><BR>Then, after you are done with the loop, do this:<BR><BR>where = Mid( where, Len(" AND ")+1 )<BR><BR>See that? You "lop off" the leading " AND "!<BR><BR>Only after that do you append the "where" value to the end of the SQL statement.<BR><BR>ALTERNATIVE:<BR><BR>Yes, you could lop the AND off the end, instead.<BR><BR>sql = Left( sql, Len(sql) - Len(" AND ") )<BR><BR>

  3. #3
    kate Guest

    Default RE: See also 'looping problem' below!

    Thanks for help but it is not working is not chopping off "AND" after the last field<BR><BR>sql=fieldname(x)&"=&#039;"&(trim(fiel dvalue(x)))&"&#039; AND "<BR> sql= Left(sql, Len(sql) - Len(" AND "))<BR>any ideas why <BR>

  4. #4
    Join Date
    Dec 1969

    Default Bill's mantra: DEBUG DEBUG DEBUG

    Looks to me like it *should* work. But when something like this happens, it is time to debug.<BR><BR>Just before the <BR><BR>sql= Left(sql, Len(sql) - Len(" AND "))<BR><BR>line, you should put in:<BR><BR>Response.Write "&#060;HR&#062;" & sql & "&lt;BR&#062;Len(sql) is " & Len(sql) & ", Left size is " & (Len(sql)-Len(" AND ")) & "&#060;HR&#062;"<BR><BR>That should give you enough info to see what is happening wrong, shouldn&#039;t it?<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