1

我正在寻找一种方法来根据另一列的数据在一个列中选择某些内容。我有 2 张桌子:

input_table - has a column called "year_of_birth"
result_table - has a column called "notes" 

你看,“notes”列可能包含一年,比如“1980”。我需要能够选择 notes 字段包含与 year_of_birth 字段匹配的行。到目前为止,我的声明是这样写的:

select inp.year_of_birth, res.notes, res.result
from order_input inp join order_result res on inp.order_id = res.order_id 
where res.result !='no match'
and res.notes like '%' + inp.year_of_birth + '%'

现在我收到一个错误,说“将 varchar 值 '%' 转换为数据类型 int 时转换失败。我不确定我做错了什么,因为我有一个类似的语句,我正在使用它有这个其中有效的字符串类型...

4

2 回答 2

2

您需要使用CONCAT而不是+

res.notes like CONCAT('%', inp.year_of_birth, '%')
于 2013-04-29T21:40:24.453 回答
0

尝试这个:

select inp.year_of_birth, res.notes, res.result from order_input as inp join order_resultas res on inp.order_id = res.order_id where res.result <> 'no match' and res.notes like CONCAT('%', inp.year_of_birth, '%')
于 2013-04-29T21:44:06.950 回答