?
Solved

SQL concat in Where clause

Posted on 2010-09-20
12
Medium Priority
?
615 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
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 1000 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 1000 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
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.
Suggested Courses

764 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