Link to home
Start Free TrialLog in
Avatar of Rick
Rick

asked on

SQL concat in Where clause

How can I accomplish this?

Select emailAddress
From UserList
Where (fname||" "||lname) =  'John Doe'
Avatar of aelliso3
aelliso3
Flag of United States of America image

Select emailAddress
From UserList
Where (fname + ' ' + lname) =  'John Doe'
Avatar of Éric Moreau
aren't the + enough:

Select emailAddress
From UserList
Where (fname + " " + lname) =  'John Doe'
Avatar of Rick
Rick

ASKER

aelliso3 - I get nothing
emoreau - Invalid column name ' '.
Try this:
 
Select emailAddress
From UserList
Where fname = 'John' and lname = 'Doe'
can you provide more information on what you are doing because the error makes no sens to me !
are you running this query from SSMS?

emoreau ... yours had 2 double quotes instead of 2 single quotes ...
Avatar of Rick

ASKER


I have this table:  

tblItems:  
ItemID, CreatedBy, CreatedDate
001, John Doe, 9/10/2010 10:15:00 PM
 

And this table:
 tblUsers:
FName, LName, Email
John, Doe, jdoe@email.com
 
I want to select the email address from tblUsers of whom created ItemID 001. In this case John Doe's email.
 
Avatar of Rick

ASKER

I'm using vb, I can split 'John Doe' and do what you said above:
 
Select emailAddress
From UserList
Where fname = 'John' and lname = 'Doe'
But I was hoping to get this accomplished directly from my SQL query.
ASKER CERTIFIED SOLUTION
Avatar of Rajkumar Gs
Rajkumar Gs
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Nice to help you :-)

It's my 400th accepted answer!

Raj