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,068 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
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.

747 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

11 Experts available now in Live!

Get 1:1 Help Now