Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select / Sub Select

Status
Not open for further replies.

sparkbyte

Technical User
Joined
Sep 20, 2002
Messages
879
Location
US
I have a table with Columns
Tracking_ID,
EmployeeID,
MachineName,
BoxNumber,
FileNumber,
TrackingDate

What I am trying to do is write a query that takes into account the fallowing.

There will be multiple FileNumbers under a TrackingNumber, but each FileNumber should be unique under that TrackingNumber. FileNumbers CAN and WILL be entered under multiple Tracking Numbers.

This is as close as I have been able to get.
Code:
SELECT    
	BoxNumber, 
	FileNumber,
	TrackingDate, 
	EmployeeID,
	MachineName
FROM         tblTrackingTable
WHERE     (TrackingDate IN
			  (SELECT     TrackingDate
				FROM          tblTrackingTable AS tblTrackingTable_1
				GROUP BY TrackingDate
				HAVING      (COUNT(BoxNumber) > 1))) AND (UPPER(FileNumber) LIKE '.box.end.')
ORDER BY BoxNumber

Thanks!!!!!!!!!

Thanks

John Fuhrman
 
Another try at it.

Code:
SELECT    
	BoxNumber, 
	FileNumber,
	TrackingDate, 
	EmployeeID,
	MachineName
FROM         tblTrackingTable
WHERE exists
	  (SELECT top 100 percent  
			BoxNumber, 
			FileNumber,
			TrackingDate, 
			EmployeeID,
			MachineName
		FROM tblTrackingTable AS T1
		GROUP BY EmployeeID, MachineName, BoxNumber, FileNumber, TrackingDate
		HAVING (COUNT(BoxNumber) > 1))
--				AND (UPPER(FileNumber) LIKE '.box.end.')
ORDER BY BoxNumber, FileNumber


Thanks

John Fuhrman
 
Can you provide sample data as it would look in the table and what results you are looking for? That would help us have a better idea of what you are looking for.

-SQLBill

The following is part of my signature block and is only intended to be informational.
Posting advice: FAQ481-4875
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top