SQL SELECT WHERE 字符串以列结尾
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25413692/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQL SELECT WHERE string ends with Column
提问by Mario M
I have this table in SQL Server 2012:
我在 SQL Server 2012 中有这个表:
Id INT
DomainName NVARCHAR(150)
And the table have these DomainName values
并且该表具有这些 DomainName 值
- google.com
- microsoft.com
- othersite.com
- google.com
- 微软网站
- 其他网站
And this value:
这个值:
mail.othersite.com
and I need to select the rows where the string ends with the column value, for this value I need to get the row no.3 othersite.com
我需要选择字符串以列值结尾的行,对于这个值,我需要获取第 3 行 othersite.com
It's something like this:
它是这样的:
DomainName Like '%value'
but in reverse ...
但反过来...
'value' Like %DomainName
回答by dotnetom
You can use such query:
您可以使用这样的查询:
SELECT * FROM TABLE1
WHERE 'value' LIKE '%' + DomainName