Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


SQL update problem

Posted on 2011-09-12
Medium Priority
Last Modified: 2012-05-12
I'm having a trouble with a simple updating statement.

I have two tables:
Table1 columns -

Table2 columns -

itemId in the two tables mean the same field. I need to select firstName and lastName from Table2 and insert "firstName, lastName " in Table1.

Here's my quesry -

update dbo.Table1
set reporterName=(
      select nn.lastName + ', ' + nn.firstName
      from dbo.Table2 nn inner join dbo.Table1 t on t.itemId=nn.itemId )
where itemId in (select rn.itemId from Table2 rn inner join dbo.Table1 tt on tt.itemId=rn.itemId)
and reporterName is null

I got the error: Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
The statement has been terminated.

Please help. Thanks.
Question by:minglelinch
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
LVL 22

Accepted Solution

pivar earned 1000 total points
ID: 36526038


I think this is what you looking for

update Table1
set reporterName=t2.lastName + ', ' + t2.firstName
from Table1 t1
join Table2 t2 on t1.itemId=t2.itemId
where t1.reporterName is null

LVL 32

Assisted Solution

by:Ephraim Wangoya
Ephraim Wangoya earned 1000 total points
ID: 36526538
update Table1
set ReportedName := ISNULL(t2.lastName + ', ', '',) + ISNULL(t2.firstName, '')
from Table2
inner join Table1 on (Table1.itemId = Table2.ItemID)
and Table1.reporterName is null

Open in new window


Author Closing Comment

ID: 36529178
Nice solution. Thank you both.

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

718 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