Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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.

721 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