?
Solved

How do I see if a recordset contains a particular value?

Posted on 2004-08-25
7
Medium Priority
?
209 Views
Last Modified: 2010-04-17
I'm a bit of a quagmire ... I need to find a way to see if a recordset contains a particular value for a field, and I need to be able to do this over and over again.  Here's my situation:

On a particular web page (ASP) I'm doing a query on an Access DB to get the field PROPID for a particular USERID.  So,
SELECT propId FROM table WHERE userID = x

In the DB table there may be multiple lines for a particular USERID, so the results might look like:
USERID      PROPID
123           222
123           333
123           444

Then listed on the web page are all of the possible PROPID's:
222      555
333      666
444      777

What I want to do is make the PROPID displaying on the web page a link IF the current user (USERID) has a record that contains that PROPID.  Otherwise, the PROPID on the web page just remains regular text.

Please let me know your thoughts on an answer to this.  Thanks.
0
Comment
Question by:griffisblessing
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 4

Expert Comment

by:jcrumble
ID: 11897344
How is the list of all possible PROPIDs being created?  If it's from the same table you could do a subquery containing Left outer join and collect just the PROPIDs for that user.  In the outer query you could build the link or an indicator based on whether the inner query value is null usnig a Case Stateent. Then you either display the column containing the link or check the indicator column in your ASP recordset  determine if you want to creat it as a link or not.  Main thing is if your end result is to display all the PROPIDs on the page then concentrate on building your SQL query so you have an easy way of knowing how to handle the recordset in your ASP Code.

Good Luck,
Jeff
0
 
LVL 4

Expert Comment

by:jcrumble
ID: 11897360
P.S. Let me know if you need an example query and I'll put one together for you.
0
 

Author Comment

by:griffisblessing
ID: 11897769
Thanks for the response jcrumble.  I'm planning to just put all of the possible PROPIDs statically on the page, then add the HREF tag values if the correct conditions are met.  Maybe this isn't possible and I need to rethink my strategy.  If you've got something better, then by all mean please share it.  For now, I'm thinking of something like this:

<table ...>
  <tr>
    <td>
      <% If conditions are met Then %>
               <a href=somepage.asp>PROPID</a>
      <% Else %>
               PROPID
      <% End If %>
    </td>
  </tr>
</table>
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Accepted Solution

by:
prashantagarw10 earned 1500 total points
ID: 11898155
Your If Condition may go like
<%
rs.MoveFirst
rs.Find("PROPID="+intPRPID)
if not rs.EOF
%>
      <a href=somepage.asp>PROPID</a>
<% Else %>
       PROPID
<% End If %>

Cheers!!!
0
 
LVL 4

Expert Comment

by:jcrumble
ID: 11898385
If it were me I would load all your PROPIDs into a "lookup table" in SQL Server.  This makes for easier maintenance and a better overall design( plus it makes the same information available for other pages/apps ithout having to maintain each set of information independently in your code).  Then use a query something like this one from Northwind (in SQL Server....sorry I don't have Access loaded on this machine):

Select A.ProductID
--, B.ProductID
, case when B.ProductID IS NULL then '0' else B.ProductID end as [Indicator]
from Products A left outer join
(Select Distinct ProductID
from "Order Details"
Where OrderID = '10643') B on
(A.ProductID = B.ProductID)
order by A.ProductID

In your case you would replace the statement
Select Distinct ProductID
from "Order Details"
Where OrderID = '10643' with your query SELECT propId FROM table WHERE userID = x

on the outside query you would hit your new lookup table similar to how I've done it in my query. You could then use the case statement to create an indicator of some kind or simply go with the B.ProductID (B.PROPID in your code) which is commented out in my Example and just check for nulls.

After getting all the information into the result set the ASP code to use should be relatively simple.  Pretty much exactly what you have listed in you code.  For your conditions you would simply check to see if the values in the result set are NULL (or '0' depending on your approach).

Alternatively you could put the tags directly in your SQL code if you have the information at that time.  Something like:

, case when B.ProductID IS NULL then '0' else '<a href=somepage.asp>'+B.ProductID+'</a>' end as [Indicator] -- you may have to cast/convert the format but it makes the asp a sinch

With this scenario you just have to display the result set period.  the browser should interpret the link and give you the results your looking for.  Something else about this design can prove to be nice.  If applicable, you could already have the links in your lookup table as a new column so that information is also easier to maintain.  If you need dynamic results on the called page based on the user you could either check add a session variable containing the user information to your query on the nect page or build it when you return the query something like:

, case when B.ProductID IS NULL then '0' else '<a href=somepage.asp?UserID='+C.UserID+'>'+B.ProductID+'</a>' end as [Indicator]
or
, case when B.ProductID IS NULL then '0' else '<a href=somepage.asp?UserID='+@UserID+'>'+B.ProductID+'</a>' end as [Indicator] -- where @USERID is the passed parameter

Hope this helps and good luck,
Jeff
0
 
LVL 4

Expert Comment

by:jcrumble
ID: 11898414
P.S. - Just because I already did it here's the SQL for putting the link directly in your data set with a cast:

Select A.ProductID
--, B.ProductID
, case when B.ProductLink IS NULL then '0'
else '<a href=something.asp>'+B.ProductLink+'</a>' end as [Indicator]
from Products A left outer join
(Select Distinct ProductID, cast(ProductID as nvarchar) as ProductLink
from "Order Details"
where OrderID = '10643') B on
(A.ProductID = B.ProductID)
order by A.ProductID

Good Luck.....again,
Jeff
0
 

Author Comment

by:griffisblessing
ID: 11903525
I've accepted the answer from prashantagarw10.  That solution was most straight-forward and easiest to implement (in my situation).  jcrumble, props go out to you for the thorough SQL explanation.  Although I'm not going to use it in this situation, I am going to keep it as a reference tool.  Hopefully it can be useful to others who browse this site.

Thanks to all for your input and suggestions.

BTW ... Here's my final code (the relevant pieces at least):

''' Pull Properties for current user
sqlProperties = "SELECT * FROM table WHERE userID = " & Request.Cookies("userID") & "; "
Set rstProperties = Server.CreateObject("ADODB.Recordset")
rstProperties.Open sqlProperties, cnnCIData, adOpenDynamic     ''' Had to open the DB this way so I could scroll through the rowsets

<% rstProperties.MoveFirst
      rstProperties.Find "propID = 111"
      If Not rstProperties.EOF Then
%>
      &raquo; <a href=somepage.asp>Prop Name</a><br>
<% Else %>
      &raquo; <font color=#C0C0C0>Prop Name</font><br>
<% End If %>
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question