I have 2 tables:
table1:
NULL NULL Cat.XX 23 Cow.XX 87
NULL NULL Tiger.XX 99 Elephant.XX
Column1 and Column2 are ID numbers that are associated with the value in column3 and column4 respectively.
table2:
84048713 Cat.XX 23 Blah1 Blah2 Blah3 Blah4
44008714 Elephant.XX 77 Blah1 Blah2 Blah3 Blah4
64038715 Cow.XX 87 Blah1 Blah2 Blah3 Blah4
34058716 Tiger.XX 99 Blah1 Blah2 Blah3 Blah4
74038717 Zebra.XX 34 Blah1 Blah2 Blah3 Blah4
94098719 Whale.XX 47 Blah1 Blah2 Blah3 Blah4
I want to update each row in table1 with the appropriate ID numbers. The resulting table1 should look like the following:
84048713 64038715 Cat.XX 23 Cow.XX 87
34058716 44008714 Tiger.XX 99 Elephant.XX
I have tried various combinations of using select, where and select replace (I use replace because the fields that contain the animal names have spaces in them). For example I tried the following:
select IDs from table2 where
(select replace("Name", ' ', '') from table2
LIKE
(select replace("Name", ' ', '') from table1)
But I get the following error:
Msg 512, Level 16, State 1, Line 1
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
I appreciate your help. Thank you.
1 Answer