SQL and ASP together

Results 1 to 4 of 4

Thread: SQL and ASP together

  1. #1
    Chris M Guest

    Default SQL and ASP together

    Let&#039;s say you have an Access database with two tables in it. The tables are "Table1" and "Table2". Table1 has five fields in it--a primary key id field, "name", "monday", "wednesday", and "friday". Table2 has two fields in it--a primary key id and "food". In Table 1, the "monday", "wednesday" and "friday" fields each represent what the person in the "name" field had for dinner that day, so each is a foreign key field correlated with the primary key field of Table2.<BR><BR>I want to use a SQL statement to join the tables so that I can post on a web page what item from the "food" field of Table2 was eaten by a person listed in the "name" field of Table1.<BR><BR>I can make the join, but when I do, the field "food" is joined to the fields "monday", "wednesday" and "friday". So, when I use &#039;Response.Write varDB("food")&#039;, ASP doesn&#039;t know if I mean the "food" field joined to "monday", the "food" field joined to "wednesday" or the "food" field joined to "friday."<BR><BR>Can anyone help me, please? Thanks.

  2. #2
    Join Date
    Dec 1969

    Default RE: SQL and ASP together

    show your quiry...

  3. #3
    Chris M Guest

    Default Mike, here's QUERY, help please...

    Okay, I can&#039;t find my query at the moment, but if I were to write one now, it would be<BR><BR>SELECT table1.id,table1.name,table1.monday,table1.wednesd ay,_ table1.friday,table2.id,table2.food FROM table1 INNER JOIN_<BR>table2 ON (table2.food=table1.monday AND_ table2.food=table1.wednesday AND table2.food=table1.friday)<BR><BR>Then, when writing ASP, I would do<BR><BR>varDB.Find "name=&#039;Robert&#039;"<BR>StrEatsThis = varDB("food")<BR>Response.Write StrEatsThis<BR><BR>except this doesn&#039;t know if I want "food" from "monday", etc.<BR><BR>I tried StrEatsThis = varDB("monday") but that only returns the number from the foreign key field. Any advice, please? Thanks.

  4. #4
    Sreedharan Surendran Guest

    Default Solution: SQL and ASP together

    Here is the query you want<BR><BR>select T1.Code , T1.Name , T2.Food , T3.Food , T4.Food<BR>from Table1 T1<BR>Join Table2 T2<BR>On T1.Monday = T2.Code<BR>Join Table2 T3<BR>On T1.Wednesday = T3.Code<BR>Join Table2 T4<BR>On T1.Friday = T4.Code

Posting Permissions

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