Solved

MS Sql Query Select Where value does not exist in another Table in Column CPE1 CPE2 CPE3 Etch

Posted on 2010-11-15
3
1,072 Views
Last Modified: 2012-05-10
Hello Experts.

I am having trouble trouble writing this query properly, what I'm trying to do is
SELECT [EQP_SERIAL_EQP], [LAST_DATE], [EQP_STAT_EQP] FROM [TechBuffer] WHERE ([TECHID] = @TECHID) AND WHERE CPETRANSMIT.CPE1 <> [EQP_SERIAL_EQP] AND CPETRANSMIT.CPE2 <> [EQP_SERIAL_EQP] etc........

Basically would like to select rows from TechBuffer Table Where [EQP_SERIAL_EQP]
does not exist in CPETransmit Table columns cpe1,cpe2,cpe3,cpe4,cpe5 .............. in the CPETransmit Table

It seems like something I should be able to do with Exist command or if anyone has a easier method.
0
Comment
Question by:marcuschang
  • 2
3 Comments
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 500 total points
ID: 34141460
SELECT [EQP_SERIAL_EQP], [LAST_DATE], [EQP_STAT_EQP]
FROM [TechBuffer] b
WHERE not exists (
      select *
      from CPETRANSMIT t
      where b.EQP_SERIAL_EQP = t.CPE1
      or b.EQP_SERIAL_EQP = t.CPE2
      or b.EQP_SERIAL_EQP = t.CPE3
      or b.EQP_SERIAL_EQP = t.CPE4
      or b.EQP_SERIAL_EQP = t.CPE5)
0
 
LVL 8

Expert Comment

by:infolurk
ID: 34141522
Where not exists syntax is;

SELECT [EQP_SERIAL_EQP], [LAST_DATE], [EQP_STAT_EQP]
FROM [TechBuffer]
WHERE not exists (select * from CPETRANSMIT Where [TechBuffer].EQP_SERIAL_EQP = CPETRANSMIT.CPE1);
0
 
LVL 8

Expert Comment

by:infolurk
ID: 34141528
Slow typer ;)
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now