CREATE TABLE #TB1 (AStr VARCHAR(100))
CREATE TABLE #TB2 (BStr VARCHAR(100))
INSERT INTO #TB1 (AStr)
SELECT '123 eesda 32421de'
UNION ALL
SELECT 'eweewew 3ed3 fdw 3232d'
INSERT INTO #TB2 (BStr)
SELECT '22123dfeesdafrwew32421de22'
UNION ALL
SELECT 'ws123fdsfsdse3eedsf'
UNION ALL
SELECT 'sd123edeweesdaferere32421de'
UNION ALL
SELECT '123dessdeesdadse32421de'
UNION ALL
SELECT '123sdeeesdafdse32421desa'
SELECT * FROM #TB2 WHERE EXISTS(SELECT * FROM #TB1 WHERE BStr LIKE '%' + REPLACE(AStr, ' ', '%') + '%')
--返回结果
22123dfeesdafrwew32421de22
sd123edeweesdaferere32421de
123dessdeesdadse32421de
123sdeeesdafdse32421desa
DROP TABLE #TB1
DROP TABLE #TB2
SQL模糊匹配查询
最新推荐文章于 2024-05-15 22:58:33 发布