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,080 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

Question has a verified solution.

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

Suggested Solutions

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

752 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