Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
1,092 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 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
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 extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

972 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