Querying with tablename and fieldname

Results 1 to 2 of 2

Thread: Querying with tablename and fieldname

  1. #1
    Mark Guest

    Default Querying with tablename and fieldname

    I&#039;m creating a search form on fields in my database. However, searches may require that I join tables with similair field names. Is there an easy way to get the table name along with the field name?<BR><BR>Example:<BR><BR>sQuery = "SELECT Person.CreationDate, Address.CreationDate FROM Person, Address INNER JOIN ON Person.ID = Address.ID" <BR><BR>rs.Open sQuery,,,adCmdTable<BR> <BR>&#039;Show fields from query<BR>for each fld in rs.fields<BR><BR>Response.write "&#060;tr&#062;&#060;td&#062;&#060;input size=50 type=""text"" name=""" & fld.name & """&#062;&#060;/td&#062;&#060;/tr&#062;"<BR><BR>next<BR><BR>I need the names of the input text boxes to be unique, not only to get the values but also so that I can query the correct field in the correct table.

  2. #2
    Join Date
    Dec 1969

    Default Use aliases via AS keyword...

    SELECT Person.CreationDate AS Person_CreationDate, Address.CreationDate AS Address_CreationDate ...<BR><BR>Give those names to the fields in the form. Now, when it is time to update, you look for the part LEFT of the underbar [e.g., using Split( Request(...), "_" ) ] and know that is the table name with the rest being the field name.<BR><BR>This assumes you have no underbars in your field names. If you do, then it&#039;ll still work, but you&#039;ll have to use INSTR instead of SPLIT, so that you ignore all but the first underbar.<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