SQL在Select语句中合并两列

编程入门 行业动态 更新时间:2024-10-22 08:23:37
本文介绍了SQL在Select语句中合并两列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如果我的数据库中有一个列为 Address1 和 Address2 的列,我该如何组合这些列,以便我只能在我的 select 语句中对其执行操作,我仍然会将它们在数据库中分开.我希望能够做到这一点

If I have a column that is Address1 and Address2 in my database, how do I combine those columns so that I could perform operations on it only in my select statement, I will still leave them separate in the database. I would like to be able to do this

WHERE completeaddress LIKE '%searchstring%'

其中已完成的地址是地址 1 和地址 2 的组合.searchstring 就像他们搜索的数据一样.因此,如果他们在 Address1 中有 '123 Center St',在 Address2 中有 'Apt 3B',如果搜索字符串是 'Center St 3B',我将如何选择它 SQL 这可能吗?

Where completedaddress is the combination of Address1 and Address2. searchstring would be like the data they searched for. So if they had '123 Center St' in Address1 and 'Apt 3B' in Address2, how would I have it select it if the searchstring was 'Center St 3B' Is this possible with SQL?

推荐答案

我想这就是你要找的 -

I think this is what you are looking for -

select Address1+Address2 as CompleteAddress from YourTable where Address1+Address2 like '%YourSearchString%'

为了防止在我们将 address1 附加到 address2 时创建复合词,您可以使用这个 -

To prevent a compound word being created when we append address1 with address2, you can use this -

select Address1 + ' ' + Address2 as CompleteAddress from YourTable where Address1 + ' ' + Address2 like '%YourSearchString%'

因此,123 Center St"和Apt 3B"不会是123 Center StApt 3B",而是123 Center St Apt 3B".

So, '123 Center St' and 'Apt 3B' will not be '123 Center StApt 3B' but will be '123 Center St Apt 3B'.

更多推荐

SQL在Select语句中合并两列

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

发布评论

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

>www.elefans.com

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