MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 28th, 2004, 04:20 PM
smac31 smac31 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 1 smac31 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Not sure if this would be a merge or an update...

Hi, I feel like this should be fairly simple but I just can't seem to get it! I basically want to update multiple records using a sub-query.

I have two tables: objects and temp1. Both have identical column names: Un_ID and SerialNum (one has serial numbers while the other has mostly Null values for the serial numbers). I want to update the SerialNum column in "objects" with the SerialNum column from temp1. The two tables can be linked by un_id's.

Here is my update statement:
UPDATE Objects
SET SerialNumber =
(SELECT SerialNumber
FROM temp1)
WHERE (objects.Un_ID = temp1.un_id)

The error I receive says "column prefix "temp1" does not match a table name or alias name used in the query".

I think the step I am missing is actually liking the two tables in the update statement. Can anyone help?

Thanks in advance!!

Reply With Quote
  #2  
Old December 29th, 2004, 04:02 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,773 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 14 h 30 m 5 sec
Reputation Power: 37
Code:
UPDATE Objects
SET SerialNumber =
(SELECT SerialNumber
FROM temp1
WHERE objects.Un_ID = temp1.un_id)
where un_id in (select un_id from temp1)

Reply With Quote
  #3  
Old December 30th, 2004, 12:34 PM
Aforsythe Aforsythe is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 104 Aforsythe User rank is Private First Class (20 - 50 Reputation Level)Aforsythe User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 22 h 8 m 10 sec
Reputation Power: 4
Wouldn't this work too Swamp?


Code:
UPDATE Objects
SET SerialNumber = temp1.SerialNumber
FROM temp1
WHERE objects.Un_ID = temp1.un_id
AND Objects.un_id in (select un_id from temp1)

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Not sure if this would be a merge or an update...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway