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
In MySQL you can use:
SELECT CONCAT(Address1, " ", Address2)
WHERE SOUNDEX(CONCAT(Address1, " ", Address2)) = SOUNDEX("Center St 3B")
The SOUNDEX
function works similarly in most database systems, I can't think of the syntax for MSSQL at the minute, but it wouldn't be too far away from the above.
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'.
If you don't want to change your database schema (and I would not for this simple query) you can just combine them in the filter like this:
WHERE (Address1 + Address2) LIKE '%searchstring%'
If your address1 = '123 Center St'
and address2 = 'Apt 3B'
then even if you combine and do a LIKE
, you cannot search on searchstring as 'Center St 3B'
. However, if your searchstring was 'Center St Apt'
, then you can do it using -
WHERE (address1 + ' ' + address2) LIKE '%searchstring%'
SELECT StaffId,(Title+''+FirstName+''+LastName) AS FullName
FROM StaffInformation
Where do you write with in the brackets this will be appear in the one single column. Where do you want a dot into the middle of the Title and First Name write syntax below,
SELECT StaffId,(Title+'.'+FirstName+''+LastName) AS FullName
FROM StaffInformation
These syntax works with MS SQL Server 2008 R2 Express Edition.