在SQLserver中使用子查询获取LIKE子句的内容

编程入门 行业动态 更新时间:2024-10-15 08:20:48
本文介绍了在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.

推荐答案

试试这个: Hi, Try this: SELECT * FROM CityTable WHERE CountryId="IND" AND CityName LIKE '%'+(SELECT CityName FROM Allcity WHERE CityID='1')+'%'

--Amit

--Amit

您好,Velkumar Kannan, 如果您的子查询返回单个值,则可以使用此查询 Hi Velkumar Kannan, If your subquery returns single value you can use this query 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子句的内容

本文发布于:2023-10-24 20:22:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1524914.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:子句   内容   SQLserver

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!