Query problem

Results 1 to 2 of 2

Thread: Query problem

  1. #1
    Join Date
    Dec 1969

    Default Query problem

    I am fairly new to asp and I have a page that I am displaying information from a table from a parameter passed from another page. I have 3 buttons that give options to view more information if the passed parameter has records in any of three other tables. For example, Table1 shows general information based on LOC_NUM. Table2, Table3, and Table4 also have the LOC_NUM field and have buttons that the user can click to access further information about LOC_NUM. What I would like to do is when my page loads with the passed LOC_NUM parameter and info from Table1, have the page also check Tables 2, 3, and 4 to see if that particular LOC_NUM is in any of those tables. If it is, I would like to have an If statement that will display a button to take the user to a page that will display further information from whichever table they have chosen, or if info is not found, print out something to that effect. I don&#039;t want the button to be printed out if there are no records for that LOC_NUM.<BR>My problem is that I&#039;m not sure of how the SQL statement should read to accomplish this. This is what I have to get the LOC_NUM from Table1:<BR>sql = "SELECT * FROM Table1 WHERE LOC_NUM = " & loc_num<BR>The way I am currently doing this is to have the buttons available all of the time, when the user clicks one of the buttons for further info, an alert box pops up telling them there are no records for that LOC_NUM. This is the code from one of the buttons: &#060;img src="../images/table2.gif" value="Table2" name="table2" onClick="location.href = &#039;select_table1.asp?LOC_NUM=&#060;%=loc_num%&# 062;&#039;"&#062;<BR>If the record is NOTFOUND on that page:<BR>if rs.EOF then<BR> response.clear<BR> response.redirect "select_table1.asp?NOTFOUND=table2&LOC_NUM=" & LOC_NUM<BR> response.end<BR>Unfortunately, this can get annoying for the user if they try several records and get that alert box. Better that they don&#039;t see the button option at all and know right away that there aren&#039;t any records.<BR><BR>I hope I have made my problem clear, thanks in advance for any help! Any advice on the best way to do this would be appreciated.<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Query problem

    Hmm... not sure I understand your question, but let&#039;s see if this helps:<BR><BR>For each button, I am assuming you are checking one of the remaining three tables, right? So... try a COUNT query:<BR><BR>Set RS = yourConn.Execute("SELECT COUNT(id) AS HasRecords FROM Table2 WHERE LOC_NUM = " & loc_num,,adCmdText)<BR>If RS("HasRecords") &#062; 0 Then<BR> &#060;show button&#062;<BR>End If<BR><BR>Hope that helps.

Posting Permissions

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