本文介绍了在SQLserver中使用子查询获取LIKE子句的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个查询

Hi,

I have a query

Select * from CityTable where CountryId="somevalue" and CityName LIKE '%andhra%'

.

取而代之的是,我想使用子查询的输出来喜欢claues

.

Instead of this i would like to use the output of a subquery to like claues

Select * from CityTable where CountryId="somevalue" and CityName LIKE '%
 here I want to use  a query(select cityname from Allcity where CityID='1')%'.



如何使用.



How can I use.

推荐答案

SELECT * FROM CityTable
WHERE CountryId="IND"
AND CityName LIKE
'%'+(SELECT CityName FROM Allcity WHERE CityID='1')+'%'



--Amit



--Amit


Select * from CityTable where CountryId="somevalue" and
CityName like '%'+ (select cityname from Allcity where CityID='1')+ '%'


Select * from CityTable
where CountryId="somevalue"
and CityName LIKE '%' + (select max(cityname) from Allcity where CityID='1') + '%'


LIKE运算符接收一个表达式,不一定是硬编码的常量.

希望这会有所帮助,
巴勃罗.


The LIKE operator receives an expression, not necesarily a hard-coded constant.

Hope this helps,
Pablo.


这篇关于在SQLserver中使用子查询获取LIKE子句的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 03:23