Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > SQL Update Statement on two tables


Reply
 
Thread Tools Display Modes
  #1  
Old 04-26-2008, 04:30 AM
eByong's Avatar
eByong eByong is offline
Regular
 
Join Date: Sep 2005
Location: Cebu Phillippines
Posts: 62
Default SQL Update Statement on two tables


hi guys im having trouble updating my two tables: nTest1 and nTest2
is it possible with sql? pls help... thanks

i want to update the emp_name column on nTest1 where the value is in nTest2 column emp_name base on emp_id...

the output basically overwrite the nTest1 emp_name column from nTest2 emp_name column base on the emp_id which is unique..

i have attached here a screenshot for details
Attached Images
File Type: jpg sql1.JPG (57.2 KB, 12 views)
__________________
________________________________________

- Don't cry bcoz its over, Smile bcoz it happens...
Reply With Quote
  #2  
Old 04-26-2008, 05:42 AM
PeetSoft's Avatar
PeetSoft PeetSoft is offline
Centurion
 
Join Date: Jun 2003
Location: HHW - the Netherlands
Posts: 161
Default

As I read it, you'll only have to update nTest1 as you're only reading from nTest2.
__________________
-----------------------------------------------------
If debugging is the art of removing bugs, then
programming must be the art of inserting them.
----------------------------------------------------- I do comply with Flyguy's signature
Reply With Quote
  #3  
Old 04-27-2008, 06:35 PM
eByong's Avatar
eByong eByong is offline
Regular
 
Join Date: Sep 2005
Location: Cebu Phillippines
Posts: 62
Default

sorry my bad yes the ntest1 emp_name column should be the only table to be updated how should i code it...my existing code does not work

Code:
UPDATE nTest1 
   SET emp_name = nTest2.emp_name
   FROM (SELECT emp_name FROM nTest2 WHERE nTest1.emp_id = nTest2.emp_id)
__________________
________________________________________

- Don't cry bcoz its over, Smile bcoz it happens...

Last edited by eByong; 04-27-2008 at 06:38 PM. Reason: no codes tag
Reply With Quote
  #4  
Old 04-28-2008, 01:33 AM
TRANSLTR's Avatar
TRANSLTR TRANSLTR is offline
Centurion
 
Join Date: Aug 2005
Location: UK
Posts: 153
Default

You're not too far off:

update ntest1 set emp_name =
(select emp_name from ntest2 where ntest1.emp_id = ntest2.emp_id)


J
__________________
Leveraging synergies to deliver outstanding customer value. And all that stuff.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->