473,804 Members | 3,113 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Finding Unique Account Numbers

Hi All. I'm trying to write an ASP page that shows me the UNIQUE account number for a customer (so I can pass it to another page) based on a search criteria. For example, I want to do a select statement on the customer table and orders table (joining on the ACCTNO) for all "Video" products.

Ex:

sq = "SELECT CUSTOMER.ACCTNO , CUSTOMER.NAME FROM CUSTOMER INNER JOIN ORDERS ON CUSTOMER.ACCTNO = ORDERS.ACCTNO
WHERE PRODUCT_TYPE = 'Video' "

Once I get the result set back I want to get a list of the UNIQUE account numbers to pass to a SQL Statement on the next page that would have a WHERE ACCTNO IN "( & var & ") " Ex:

sql = "SELECT * FROM CUSTOMER WHERE ACCTNO IN (" & AcctList & ") "

What I was trying to do (in the first result set) was something like this:

do while not rs.eof
AcctList = AcctList & trim(rs("ACCTNO ")) & ","
rs.movenext
loop

AcctList = Left(AcctList, len(AcctList) - 1)

The problem is that the list I get back looks like this:

(42,42,42,42,31 ,31,56,56,56,56 ,56,56,70,77,77 ,77 ....... etc )

How do I get just ONE account number for the search criteria?

Thanks
Jul 19 '05 #1
3 1933
David Berry wrote:
Hi All. I'm trying to write an ASP page that shows me the UNIQUE
account number for a customer (so I can pass it to another page)
based on a search criteria. For example, I want to do a select
statement on the customer table and orders table (joining on the
ACCTNO) for all "Video" products.

Ex:

sq = "SELECT CUSTOMER.ACCTNO , CUSTOMER.NAME FROM CUSTOMER INNER JOIN
ORDERS ON CUSTOMER.ACCTNO = ORDERS.ACCTNO
WHERE PRODUCT_TYPE = 'Video' "

Once I get the result set back I want to get a list of the UNIQUE
account numbers I am assuming there is only one account number per customer. If I'm wrong,
this suggestion will need to be amended.

Use either GROUP BY, or the DISTINCT keyword in your query (please use table
aliases to make your queries more readable).

sq = "SELECT c.ACCTNO, c.NAME FROM CUSTOMER c INNER JOIN ORDERS oON c.ACCTNO
= o.ACCTNO WHERE PRODUCT_TYPE = 'Video' GROUP BY c.ACCTNO, c.NAME "

or

sq = "SELECT DISTINCT c.ACCTNO, c.NAME FROM CUSTOMER c INNER JOIN ORDERS o
ON c.ACCTNO = o.ACCTNO WHERE PRODUCT_TYPE = 'Video' "
to pass to a SQL Statement on the next page that would have a WHERE ACCTNO IN "( & var & ") " Ex:
sql = "SELECT * FROM CUSTOMER WHERE ACCTNO IN (" & AcctList & ") "


Don't use selstar. Always specify the fields you want to retrieve so ADO
does not have to make an extra trip to the database to resolve the * into
the actual field names.

I'm not clear on the need to do this. IN (<list>) is not very efficient. It
should be avoided when there is a more efficient method. In this case, your
first query already returns the list of account numbers you're interested
in. Why not just use the PRODUCT_TYPE criterion again to retrieve these new
results? It should be more efficient than using IN (<list>) ...

HTH,
Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #2
Hi Bob. Thanks. I tried DISTINCT and GROUP BY but that didn't work. Yes,
there is one unique account number for each customer. See if this makes
more sense:

On the first ASP page I'm doing a select of a bunch of fields from the
CUSTOMER and ORDERS table joining on ACCTNO. Then I display a table that
show the number of order <30 Days Past Due, 30-60 Days Past Due etc... When
they click on "VIEW" (next to that column) I send the AcctList to the second
page that pulls up a list all of the customers.

So the first page might be:

<30 = 13 VIEW
30-60 = 4 VIEW
60 - 90 = 5 VIEW

The first select looks like this:

SELECT DISTINCT c.ACCTNO As Acct, s.SHIPDATE, DATEDIFF(day, s.SHIPDATE,
GETDATE()) AS DUEDAYS FROM s INNER JOIN ORDERS o ON s.ORDNO = o.ORDNO INNER
JOIN CUSTOMER c ON o.ACCTNO = c.ACCTNO WHERE o.orederrep = 'Matt' AND
o.oredertype = 'Video' ORDER BY DUEDAYS DESC

I then try and loop through to create a list of acct numbers to pass to the
next page

To create the list I was doing this:

do while not rs.eof
AcctList = AcctList & trim(rs("Acct") ) & ","
rs.movenext
loop

In the above case there's only one customer - #53, but I get a list like
(53,53,53,53,53 ,53,53)

When they click on "View" I pass AcctList to the next page to fill the
SELECT statement, Ex:

sql = "SELECT * FROM CUSTOMER WHERE ACCTNO IN (" & AcctList & ") "

(No, I'm not using SELECT * I just didn't want to type all the field names
here).

The reason I wanted to use the IN statement is because all the second page
is doing is pulling back a list of all the customer names that met the
criteria from the page before. For example, all customers that are 30 days
past due.

Does that help explain it better?

Thanks!
"Bob Barrows" <re******@NOyah oo.SPAMcom> wrote in message
news:ui******** ******@TK2MSFTN GP11.phx.gbl...
David Berry wrote:
Hi All. I'm trying to write an ASP page that shows me the UNIQUE
account number for a customer (so I can pass it to another page)
based on a search criteria. For example, I want to do a select
statement on the customer table and orders table (joining on the
ACCTNO) for all "Video" products.

Ex:

sq = "SELECT CUSTOMER.ACCTNO , CUSTOMER.NAME FROM CUSTOMER INNER JOIN
ORDERS ON CUSTOMER.ACCTNO = ORDERS.ACCTNO
WHERE PRODUCT_TYPE = 'Video' "

Once I get the result set back I want to get a list of the UNIQUE
account numbers I am assuming there is only one account number per customer. If I'm wrong,
this suggestion will need to be amended.

Use either GROUP BY, or the DISTINCT keyword in your query (please use

table aliases to make your queries more readable).

sq = "SELECT c.ACCTNO, c.NAME FROM CUSTOMER c INNER JOIN ORDERS oON c.ACCTNO = o.ACCTNO WHERE PRODUCT_TYPE = 'Video' GROUP BY c.ACCTNO, c.NAME "

or

sq = "SELECT DISTINCT c.ACCTNO, c.NAME FROM CUSTOMER c INNER JOIN ORDERS o
ON c.ACCTNO = o.ACCTNO WHERE PRODUCT_TYPE = 'Video' "
to pass to a SQL Statement on the next page that would have a WHERE ACCTNO IN "( & var & ") " Ex:

sql = "SELECT * FROM CUSTOMER WHERE ACCTNO IN (" & AcctList & ") "


Don't use selstar. Always specify the fields you want to retrieve so ADO
does not have to make an extra trip to the database to resolve the * into
the actual field names.

I'm not clear on the need to do this. IN (<list>) is not very efficient.

It should be avoided when there is a more efficient method. In this case, your first query already returns the list of account numbers you're interested
in. Why not just use the PRODUCT_TYPE criterion again to retrieve these new results? It should be more efficient than using IN (<list>) ...

HTH,
Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Jul 19 '05 #3
David Berry wrote:
Hi Bob. Thanks. I tried DISTINCT and GROUP BY but that didn't work.
Yes, there is one unique account number for each customer. See if
this makes more sense:

On the first ASP page I'm doing a select of a bunch of fields from the
CUSTOMER and ORDERS table joining on ACCTNO. Then I display a table
that show the number of order <30 Days Past Due, 30-60 Days Past Due
etc... When they click on "VIEW" (next to that column) I send the
AcctList to the second page that pulls up a list all of the customers.

So the first page might be:

<30 = 13 VIEW
30-60 = 4 VIEW
60 - 90 = 5 VIEW

The first select looks like this:

SELECT DISTINCT c.ACCTNO As Acct, s.SHIPDATE, DATEDIFF(day,
s.SHIPDATE, GETDATE()) AS DUEDAYS FROM s INNER JOIN ORDERS o ON
s.ORDNO = o.ORDNO INNER JOIN CUSTOMER c ON o.ACCTNO = c.ACCTNO WHERE
o.orederrep = 'Matt' AND o.oredertype = 'Video' ORDER BY DUEDAYS DESC

I then try and loop through to create a list of acct numbers to pass
to the next page

To create the list I was doing this:

do while not rs.eof
AcctList = AcctList & trim(rs("Acct") ) & ","
rs.movenext
loop

In the above case there's only one customer - #53, but I get a list
like (53,53,53,53,53 ,53,53)

When they click on "View" I pass AcctList to the next page to fill the
SELECT statement, Ex:

sql = "SELECT * FROM CUSTOMER WHERE ACCTNO IN (" & AcctList & ") "
The reason I wanted to use the IN statement is because all the second
page is doing is pulling back a list of all the customer names that
met the criteria from the page before. For example, all customers
that are 30 days past due.

Does that help explain it better?

Sorry, but no. I don't understand why you don't use the ">30" (for example)
criterion to get the results for the second page.

A picture is worth a thousand words. Could you show a few rows of sample
data in tabular format for the CUSTOMERS and ORDERS tables. Just the minimum
columns to illustrate the problem. Then show the results you want to show on
each page.

Also tell us what database you are using.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
10767
by: August1 | last post by:
A handful of articles have been posted requesting information on how to use these functions in addition to the time() function as the seed to generate unique groups (sets) of numbers - each group consisting of 6 numbers - with a total of 50 groups of numbers. A well-known girl that some publishing companies use to provide introductory level textbooks to various Junior Colleges in the U.S., not surprisngly, asks for this same exact...
6
4628
by: GSpiggle | last post by:
I have a database with records that should have a consecutive number ID (Check Register). Also has other records (deposits and adjusting entries) that don't fit in the number range so autonumbering isn't the answer. I want to check to see if any check numbers are missing from the register, but can't figure out how to accomplish it. Thanks for any help.
2
6847
by: D | last post by:
My first attempt at this and I'm searching formulas like so RIGHT(TEXT(A15,'yy'),1)*1000+A15-CONCATENATE(1,'-','jan','-',TEXT(A15,'yy'))+1 I want to extract the row / col coordinates (A15 in above) so I'm using this +\d+\d* however I want unique ones and not 3 copies of A15 as the above returns.
9
12574
by: dave m | last post by:
I need to be able to retrieve a unique ID from a users PC. I needs to be something a user could not easily change, like the computer name. Could someone point me in the right direction to find the information found in Windows system information? Or maybe there is a better method. Thanks in advance for any help or suggestions. Dave M.
3
1721
by: deaddog4201 | last post by:
How can i save a .txt file where the name of the file would be the result of the selection made from a Dom tree view's parent node tag in visual basic? So for example i have an editable tree view form i add an entry to the tree view when i save it another process is started "part of which is an encryption scheme" the important part i need help with is saving the sharedkey as the value of the elements parent tag applied to a new addition to the...
2
4453
by: srusskinyon | last post by:
I need some help getting unique records from our database! I work for a small non-profit homeless shelter. We keep track of guest information as well as what services we have offered for statistical purposes. I've been using Here's the situation: I have two main tables:
5
1887
by: Ramdas | last post by:
I am doing some HTML scrapping for a side project. I need a method using sgmllib or HTMLParser to parse an HTML file and get line nos of all the tags I tried a few things, but I am just not able to work with either if the parsers.
3
1843
by: tkpmep | last post by:
I have coded a robust (Theil-Sen) regression routine which takes as inputs two lists of numbers, x and y, and returns a robust estimate of the slope and intercept of the best robust straight line fit. In a pre-processing phase, I create two new lists, x1 and y1; x1 has only the unique values in x, and for each unique value in x1, y1 has the median of all such values in x. My code follows, and it seems a bit clumsy - is there a cleaner...
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10578
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10321
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10077
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9152
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6853
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.