troubleshooting Question

Sql select problem

Avatar of Brock
BrockFlag for Canada asked on
Microsoft SQL ServerSQL
6 Comments3 Solutions70 ViewsLast Modified:
Hello,

The following is the data that I need to model in sql :

runcntl          OPRID      EMPLID       cntrct    DEPTID              
TEST               L             2001548      148137      8437             
TEST               L              2001548 148137      8500             
TEST             L               2001548 148139      8450             
TEST            L             2001548      148139      8460             
TEST            L               4086876      148140      8370             
TEST            L               4088876  148151      8370             
TESTS            L               4088876      148152      8370             
TEST           L              9700994 148150      8360             
TEST           L             9700994      148150      8370             
TEST           L             4086876      148152      8370             


I do not want  the values below to appear in the result

TEST   L      4088876      148151      8370
TEST   L      4088876      148152      8370
TEST   L      4086876      148152      8370


So I only want the EMPLID who have different deptids either within a single cntrct or across multiple cntrcts.

Can this be done without a CTE?

Thanks, Brock
ASKER CERTIFIED SOLUTION
David Todd
Senior Database Administrator

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 3 Answers and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros