Solved

SQL concat in Where clause

Posted on 2010-09-20
12
611 Views
Last Modified: 2012-05-10
How can I accomplish this?

Select emailAddress
From UserList
Where (fname||" "||lname) =  'John Doe'
0
Comment
Question by:Rick
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 11

Expert Comment

by:aelliso3
ID: 33717841
Select emailAddress
From UserList
Where (fname + ' ' + lname) =  'John Doe'
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 33717850
aren't the + enough:

Select emailAddress
From UserList
Where (fname + " " + lname) =  'John Doe'
0
 
LVL 13

Author Comment

by:Rick
ID: 33717875
aelliso3 - I get nothing
emoreau - Invalid column name ' '.
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 11

Expert Comment

by:aelliso3
ID: 33717896
Try this:
 
Select emailAddress
From UserList
Where fname = 'John' and lname = 'Doe'
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 33717910
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?
0
 
LVL 11

Expert Comment

by:aelliso3
ID: 33717932

emoreau ... yours had 2 double quotes instead of 2 single quotes ...
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 33717989
doh!
0
 
LVL 13

Author Comment

by:Rick
ID: 33718022

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.
 
0
 
LVL 13

Author Comment

by:Rick
ID: 33718041
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.
0
 
LVL 23

Accepted Solution

by:
Rajkumar Gs earned 250 total points
ID: 33718169
Check the attached script.

Raj
create table #tblUsers
(
	FName  varchar(25), 
	LName		varchar(25), 
	Email	varchar(25)
)

insert into #tblUsers
select 'John', 'Doe', 'jdoe@email.com '


select * from #tblUsers where FName +  ' ' + LName =  'John Doe' 

drop table #tblUsers

Open in new window

0
 
LVL 11

Assisted Solution

by:aelliso3
aelliso3 earned 250 total points
ID: 33718211
Select *
from tblItems
     INNER JOIN tblUsers
          ON tblItems.CreatedBy = tblUsers.FName + ' ' + tblUsers.FName

Then you can use any field to get the values you want
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 33759931
Nice to help you :-)

It's my 400th accepted answer!

Raj
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question