Solved

Very simple MSSQL syntax question

Posted on 2009-04-11
3
158 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
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you for your help.
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

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

16 Experts available now in Live!

Get 1:1 Help Now