如何确定一列中的字符串是否在另一列中?

时间:2020-12-11 22:14:18

I need to see if a string from one column is located in another column. What's a good way to do that please?

我需要查看一列中的字符串是否位于另一列中。有什么好办法吗?

Table:

表:

如何确定一列中的字符串是否在另一列中?

Desired Results:

期望的结果:

如何确定一列中的字符串是否在另一列中?

SQL:

SQL:

DROP TABLE ##SCHOOLS

CREATE TABLE ##SCHOOLS(
SchoolName   varchar(50),
ChoiceSchool varchar(50),
)

INSERT INTO ##SCHOOLS
(SchoolName, ChoiceSchool)
VALUES 
('Smith HS', 'Smith'),
('Jones High', 'Jones'),
('Eagle Elementary School', 'Eagle'),
('Hawk ES', 'Dunham'),
('No241', 'Harris'),
('*field Middle', '*field')

SELECT 
ChoiceSchool
,SchoolName
FROM ##SCHOOLS

Thank you for your help.

感谢您的帮助。

1 个解决方案

#1


4  

You can use like operator. For your particulare case it should be:

你可以使用like运算符。对于您的特殊情况,它应该是:

SELECT 
    ChoiceSchool,
    SchoolName
FROM ##SCHOOLS
WHERE SchoolName like '%' + ChoiceSchool + '%'

#1


4  

You can use like operator. For your particulare case it should be:

你可以使用like运算符。对于您的特殊情况,它应该是:

SELECT 
    ChoiceSchool,
    SchoolName
FROM ##SCHOOLS
WHERE SchoolName like '%' + ChoiceSchool + '%'