问题描述
如果我的数据库中有一个列为 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语句中合并两列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!