Solved

Help with update query

Posted on 2008-10-29
3
211 Views
Last Modified: 2012-05-05
This has to got to be so simple but I can't get it to work....
I am trying to update 2 fields per record based on the results of a query. I can run the query by itself and it returns the data but when i add the update piece it balks about a ")" issue. I can't seem to find out why or where to put the closing ")". What am I missing???

use netperfmon
UPDATE dbo.nodes
set totalports = c.totalports,
freeports=c.freeports
from (
SELECT c.totalports, c.freeports
FROM [MyServer]...[truecontrol.rn_device] as C
JOIN dbo.nodes as N
on N.caption = c.hostname)
0
Comment
Question by:edrz01
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 125 total points
ID: 22830235
this will work better:
use netperfmon
UPDATE n
  set totalports = c.totalports,
  freeports=c.freeports
from dbo.nodes n
join [MyServer]...[truecontrol.rn_device] as C
  on N.caption = c.hostname

Open in new window

0
 

Author Closing Comment

by:edrz01
ID: 31511116
Once again, right on.  Looks like I need to spend a little more time on my SQL sysntax review....
THANKS!
0
 
LVL 9

Expert Comment

by:jamesgu
ID: 22830291
c is not visible from outside of the brackets, and the update clause expects an alias of the derived table

try this

use netperfmon
UPDATE dbo.nodes
set totalports = tt.totalports,
freeports=tt.freeports
from (
SELECT c.totalports, c.freeports
FROM [MyServer]...[truecontrol.rn_device] as C
JOIN dbo.nodes as N
on N.caption = c.hostname) tt
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

775 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