Sql server 在非字母字符串中查找字符串
我必须找出表中所有出现的字母字符串。为此,我使用以下算法(我在循环中遍历另一个表以获得这个@TableName值): 此条件是错误的,因为它还显示另一个字符串中包含的字符串 让我们假设@TableName=test。我想在表中查找记录,该表包含此字符串(也由非字母字符放弃)。我的算法返回包含以下内容的行:Sql server 在非字母字符串中查找字符串,sql-server,string,tsql,Sql Server,String,Tsql,我必须找出表中所有出现的字母字符串。为此,我使用以下算法(我在循环中遍历另一个表以获得这个@TableName值): 此条件是错误的,因为它还显示另一个字符串中包含的字符串 让我们假设@TableName=test。我想在表中查找记录,该表包含此字符串(也由非字母字符放弃)。我的算法返回包含以下内容的行: test (test) test0x test02 _test_2222 pretest <--- uptest <---- ... 测试 (测试) test0x 测试02 _测
test
(test)
test0x
test02
_test_2222
pretest <---
uptest <----
...
测试
(测试)
test0x
测试02
_测试单元2222
预测试尝试下一个查询:
DECLARE @TableName VARCHAR(128) = 'test' -- Replace with propper data type and max length
SELECT *
FROM (VALUES
('test'),
('(test)'),
('test0x'),
('test02'),
('_test_2222'),
('pretest '),
('uptest'),
('testAlpha'),
('13223 tes3432')
) t(Col1)
WHERE t.Col1 LIKE '%' + @TableName + '%'
AND NOT(t.Col1 LIKE '%[a-z]' + @TableName + '%' OR t.Col1 LIKE '%' + @TableName + '[a-z]%')
您已经发布了算法结果,但是您的预期结果如何?我不需要最后两个(用箭头标记)字符串。
DECLARE @TableName VARCHAR(128) = 'test' -- Replace with propper data type and max length
SELECT *
FROM (VALUES
('test'),
('(test)'),
('test0x'),
('test02'),
('_test_2222'),
('pretest '),
('uptest'),
('testAlpha'),
('13223 tes3432')
) t(Col1)
WHERE t.Col1 LIKE '%' + @TableName + '%'
AND NOT(t.Col1 LIKE '%[a-z]' + @TableName + '%' OR t.Col1 LIKE '%' + @TableName + '[a-z]%')