Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / Programming / SQL / July 2008

Tip: Looking for answers? Try searching our database.

Query Suggestions?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Wright - 22 Jul 2008 14:35 GMT
I have a problem.  I just inherited a program that is full of holes and bugs
and I need to do some patching.  Just to note everyone, I did not set up
this database and I did not code this program, I am stuck with it as is.
That being said,  I have to do some checks on a database to make sure pairs
of material are in the same carton.

For example.  In carton 12345 pieces 1A and 1B must be in the carton.

The table is set up as follows:

Piece varchar(12)
InspectedByDate Datetime
InspectedBy varchar(20)
CartonNumber varchar(15)
Traveler varchar(8)

So the data should look like the following:

1A    5/5/2008    RR    081064    55132R
1B    5/5/2008    RR    081064    55132R
2A    5/5/2008    RR    081064    55132R
2B    5/5/2008   RR    081064    55132R
...

I can do a quick check to make sure there are an even number in the carton,
what I need help on is matching up the A and B pairs in the table.  I though
of grabbing all the "A" pieces then using a sub-query to do a like search
for "B" pieces, but am stuck. Anyone have any suggestions?

John
Paddy - 22 Jul 2008 14:44 GMT
Select * from

(
Select
Piece ,
InspectedByDate,
InspectedBy,
CartonNumber,
Traveler
where piece like '%A'
)
a
full outer join
(
Select
Piece ,
InspectedByDate,
InspectedBy,
CartonNumber,
Traveler
where piece like '%B'
)
b
on a.InspectedByDate = b.InspectedByDate
and a.InspectedBy = b.InspectedBy
and a.CartonNumber = b.CartonNumber
and a.Traveler  = b.Traveler

If you get any nulls on either the left or right hand side that will
highlight a missing record.

you should check the joins as they maybe too restrictive.

Paddy
Plamen Ratchev - 22 Jul 2008 15:47 GMT
I believe you already posted the same question yesterday and had good
answers:
http://groups.google.com/group/microsoft.public.sqlserver.programming/browse_frm
/thread/3f73500d2957d796?hl=en
#

HTH,

Plamen Ratchev
http://www.SQLStudio.com
John Wright - 22 Jul 2008 17:16 GMT
Sorry for the double post, but this my last post did not show up in my
newsreader. I apologize and thank everyone for the help.

John
>I believe you already posted the same question yesterday and had good
>answers:
[quoted text clipped - 4 lines]
> Plamen Ratchev
> http://www.SQLStudio.com
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.