-
combine columns with SELECT
Hello, I've searched for this solution but none have worked for me so I thought I ask directly.
I have a variable called "name"
I have a DB which contains 2 columns: FirstName and LastName
how can I create a query like:
SELECT First.Name, LastName FROMl dbo.Actors
WHERE First.Name+ ' '+LastName = "Elijah Wood"
The string "Elijah Wood" has a 'SPACE'.
Thanks in advance for any assistance.
--
Jeff
-
You just did, use single quote for string instead of double quote and you are good to go.
SELECT First.Name, LastName FROMl dbo.Actors
WHERE FirstName+ ' '+LastName = 'Elijah Wood'
-
SELECT First.Name, LastName FROM dbo.Actors
WHERE First.Name = 'Elijah' and LastName = 'Wood'
-
Obviously care must be taken when concattenating columns and strings together and comparing. Are the columns varchar or fixed length?. Strip or Trim functions may be used if valid in your RDBMS.
-
Originally Posted by skhanal
You just did, use single quote for string instead of double quote and you are good to go.
SELECT First.Name, LastName FROMl dbo.Actors
WHERE FirstName+ ' '+LastName = 'Elijah Wood'
Thanks skhanal, I had tried that as well (single quotes). The query doesn't complain, it just doesn't return a record. I only get the column headings: FirstName LastName
-
Originally Posted by MikeH
Obviously care must be taken when concattenating columns and strings together and comparing. Are the columns varchar or fixed length?. Strip or Trim functions may be used if valid in your RDBMS.
Mike, you may have hit onto something: the columns are both nchar(20)
I'm using sqlserver express, I'll look into the strip or trim functions.
-
Originally Posted by jboyd111
Mike, you may have hit onto something: the columns are both nchar(20)
I'm using sqlserver express, I'll look into the strip or trim functions.
I figured it out, thanks to the suggestions I read here. The code that works is:
SELECT First.Name, LastName FROM dbo.Actors
WHERE LTRIM(RTRIM(FirstName))+ ' '+LTRIM(RTRIM(LastName) = 'Elijah Wood'
Thanks to everyone for your assistance!
------------
Jeff
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|