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
Be aware that using expressions as join predicates will force the optimizer to ignore indices on those columns.
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.