?
Solved

Help with update query

Posted on 2008-10-29
3
Medium Priority
?
241 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 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

621 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