If yo can guarantee that there is only 1 match in the 2nd table and to only over want 2 [Id] columns returned then this will do itDECLARE @matchString VARCHAR(255) SET @matchString = 'foo1'DECLARE @table1 TABLE ( [name] VARCHAR(255) , [ID] INT )DECLARE @table2 TABLE ( [name] VARCHAR(255) , [Id] INT )INSERT @table1 ([name], [Id]) SELECT 'apples', 10UNION SELECT 'oranges', 20INSERT @table2 ([name], [ID]) SELECT 'foo1apples', 23UNION SELECT 'foo1oranges', 1UNION SELECT 'abcapples', 10SELECT * FROM @table1SELECT * FROM @table2SELECT t1.[name] AS [Name] , t1.[ID] AS [Id1] , t2.[ID] AS [Id2]FROM @table1 t1 JOIN @table2 t2 ON @matchString + t1.[name] = t2.[name]
However, I suspect that isn't what you want.....Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION