Quantcast
Channel: Help in join with logic
Viewing all articles
Browse latest Browse all 8

Help in join with logic

$
0
0

That wasn't part of your original requirement, which is why no one accounted for it.

Try:

DECLARE @A TABLE (Ename char(10), ED char(4), EE char(4), EG char(4))
INSERT INTO @A (Ename, ED, ee, eg) VALUES
('214129-03','03','CAS','GRP'),
('214130-04','04','PER','GRP'),
('214132-06','06','CAS','GRP')

DECLARE @B TABLE (Ename1 char(10), ED1 char(4), EE1 char(4), EG1 char(4))
INSERT INTO @B (Ename1, ED1, EE1, EG1) VALUES
('214129','03','CAS','GRP'),
('214130','04','CAS','GRP'),
('214132','06','TAS','GRP')

SELECT *
  FROM @A a
    INNER JOIN @b b
	  ON LEFT(a.ename,CHARINDEX('-',a.ename)-1) = b.Ename1
	  AND (
	       a.ED <> b.ED1
	    OR a.EE <> b.EE1
		OR a.EG <> b.EG1
		  )


Don't forget to mark helpful posts, and answers. It helps others to find relevant posts to the same question. Enjoyed my post? Hit the up arrow (left)
Really enjoyed it? See my profile!
My Tech Net Articles.


Viewing all articles
Browse latest Browse all 8

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>