SQL Combine Two Columns in Select Statement

前端 未结 5 1536
栀梦
栀梦 2020-12-03 10:23

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

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-03 10:31

    I think this is what you are looking for -

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

    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%'
    

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

提交回复
热议问题