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
Solved

SQL update problem

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

I have two tables:
Table1 columns -
id1
itemId
reporterName
other
...

Table2 columns -
id2
itemId
firstName
lastName
otherfld
...

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.
0
Comment
Question by:minglelinch
3 Comments
 
LVL 22

Accepted Solution

by:
pivar earned 250 total points
ID: 36526038

Hi,

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


/peter
0
 
LVL 32

Assisted Solution

by:ewangoya
ewangoya earned 250 total points
ID: 36526538
try
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

0
 
LVL 1

Author Closing Comment

by:minglelinch
ID: 36529178
Nice solution. Thank you both.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

860 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