I have this query
INNER JOIN view AS vw ON vw.[Id] = vw2.[Id]
INNER JOIN view AS vw ON vw.[Id] = Replace(vw2.[Id], char(9), '')
SELECT * FROM database.view2 WHERE REPLACE(Id, char(9), '') = '2012 '
I suspect there may be more characters you're dealing with than just a tab. For example, you include
REPLACE(Id, char(9), '') = '2012 '
Why is there still a space on the end after the replace?
I was able to get your method to work in SQL 2008R2, so below is proof-of-concept code.
CREATE TABLE #table1 ( Id varchar(5) ) CREATE TABLE #table2 ( Id varchar(5) ) INSERT INTO #table1 VALUES ('2012') ,('2013') ,('2014') ,('2015') ,('2016') INSERT INTO #table2 VALUES ('2012'+CHAR(9)) ,('2013'+CHAR(9)) ,('2014'+CHAR(9)) ,('2015'+CHAR(9)) ,('2016'+CHAR(9)) SELECT t1.Id, t2.Id FROM #table1 t1 INNER JOIN #table2 t2 ON t1.Id = REPLACE(t2.Id,CHAR(9),'')
See if that gives you the proper results - it does for me.