|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
March 31st, 2005, 12:13 PM
|
Registered User
|
|
Join Date: Mar 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Distinct SELECT DISTINCT question...
Okay... Here is my conundrum. I have a table of products. This table is a list of products with associated components listed under one specific system number:
Sysno | Item Number | Description | Rate
----------------------------------------
1 | C123C | Laptop | 250
1 | A987A | Lap. Memory |
1 | A876A | Lap. Case |
2 | C234C | Projector | 300
2 | A765A | Proj. Case |
2 | A654A | Proj. Bulb |
3 | C345C | Technician | 50
3 | A543A | Travel |
I realize that this is NOT an ideal product list, but I cannot modify it as it is the company's master database for a completely different complex piece of software.
I want to select all the data from each row (like SELECT *) BUT I only want the first of the distinct Sysno fields so my recordset would look like this:
Sysno | Item Number | Description | Rate
----------------------------------------
1 | C123C | Laptop | 250
2 | C234C | Projector | 300
3 | C345C | Technician | 50
How can I accomplish this through a heavily modified Select statement?
Thank you all SO much in advance!
|
March 31st, 2005, 03:16 PM
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Try this..not sure what databae are you using
SQL Server T-SQL Query
SELECT Sysno,Item_Number,[Description],Rate
From Table
Group By Sysno,Item_Number,[Description],Rate
Having Rate IS NOT NULL
|
April 1st, 2005, 11:20 AM
|
Registered User
|
|
Join Date: Mar 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hmmm, I guess I didn't specify too much.
My bad...
I am programming in VBscript, pulling data through ODBC from a FoxPro Database.
Also, I would really like to have the SQL statement select the distinct products via the Sysno. This way, I dont take a chance on their being additional rate data that would throw the statement off. I know for sure that the Sysno data will not change.
|
April 6th, 2005, 10:23 AM
|
Authorized User
|
|
Join Date: Mar 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Try using SELECT DISTINCT Sysno, Item Number, Description, Rate FROM TableName.
|
August 18th, 2005, 08:53 AM
|
Registered User
|
|
Join Date: Jun 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
EndEffect,
Given that you are using ODBC with a Foxpro database, you could do the following:
SELECT * FROM MyTable GROUP BY Sysno
Note that this is not normally legal SQL syntax, but it works with the Foxpro ODBC driver because the driver is up to date only as of Visual FoxPro 6.0, and that version was very forgiving of this syntax. It should produce the result you want.
Mike
|
|
|