Solved

Very simple MSSQL syntax question

Posted on 2009-04-11
3
165 Views
Last Modified: 2012-05-06
Hi,

Why does this query give me a syntax error in MS SQL Server?

select dv_id, dp_id from em where dv_id, dp_id not in (select dv_id, dp_id from dp)

I'm just trying to check for invalid data for a foreign key referencing a two-part primary key.

What is the correct syntax for this? Thanks in advance.
0
Comment
Question by:algernon23
[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
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 50 total points
ID: 24121882
this will do:
select dv_id, dp_id from em where not exists (select null from dp where dp.dv_id = em.dv_id and dp.dp_id = em.dp_id) 

Open in new window

0
 
LVL 11

Expert Comment

by:bmatumbura
ID: 24121884
Your subquery (select dv_id, dp_id from dp) must not return multiple fields if you want to use the NOT in clause
0
 

Author Closing Comment

by:algernon23
ID: 31569162
Thank you for your help.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 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