Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 3rd, 2007, 05:04 AM
Friend of Wrox
Points: 718, Level: 10
Points: 718, Level: 10 Points: 718, Level: 10 Points: 718, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: Ennis, Clare, Ireland.
Posts: 131
Thanks: 10
Thanked 0 Times in 0 Posts
Default SQL Update query (error message)

Hi,

I have a problem when executing the following SQL 2000 query (Query Analyser). The field is updated (a single row table) when executed, however, there is an associated error message which I don't want, as this is to become a step within an automated DTS package:

Code:
UPDATE dbo.Update_Status 
SET dbo.Update_Status.CurStatus = '19'
SELECT dbo.Mer_Sales.Division_Reference, 
dbo.Update_Status.CurStatus
FROM 
dbo.Mer_Sales.Division_Reference, 
dbo.Update_Status.CurStatus
WHERE (((dbo.Update_Status.CurStatus)='18') AND 
((dbo.Mer_Sales.Division_Reference)="1"));
Despite the error message below, the fields do exist. What am I doing wrong?

Output:
(1 row(s) affected)

Server: Msg 208, Level 16, State 1, Line 4
Invalid object name 'dbo.Mer_Sales.Division_Reference'.
Server: Msg 208, Level 16, State 1, Line 4
Invalid object name 'dbo.Update_Status.CurStatus'.



A further inconsistency is that the '1 row(s) affected' occurs when I run the update query for a 2nd, 3rd time etc.

ONLY as a last resort, maybe I can trap for the error message (but how do I do this?).

Thanks in advance,


Neal

A Northern Soul
__________________
Neal

A Northern Soul
Reply With Quote
  #2 (permalink)  
Old August 3rd, 2007, 08:57 PM
Friend of Wrox
Points: 1,536, Level: 15
Points: 1,536, Level: 15 Points: 1,536, Level: 15 Points: 1,536, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: , MI, USA.
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

First, you're missing a join condition in the WHERE clause... you've created a partial cross-join because you're missing a relationship between the two tables... you need something that says...

AND dbo.Update_Status.somecolumn = dbo.Mer_Sales.somecolumn

Also, you really need to read about the UPDATE statement in Books Online and look at some of the examples there... what you need to end up with is something that looks more like this...

UPDATE us
SET CurStatus = '19'
FROM dbo.Mer_Sales ms,
     dbo.Update_Status us
WHERE us.CurStatus='18'
AND ms.Division_Reference='1'
AND you_are_missing_a_join_condition_to_relate_the_two _tables

Keywords to study in Books Online

JOINS
SELECT
TABLE ALIAS
UPDATE
FROM

--Jeff Moden
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Update table using SQL query from form pater53 Access VBA 4 January 24th, 2007 11:24 AM
Append Query Error Message Misleading SerranoG Access 2 April 3rd, 2006 12:52 PM
Update query equivalent in SQL Mitch SQL Server 2000 5 May 5th, 2005 05:14 AM
SQL Update query morne Access 11 December 17th, 2004 01:47 PM
Query String Too Long....Max Length Error Message phungleon Classic ASP Databases 14 May 28th, 2004 12:25 PM



All times are GMT -4. The time now is 01:21 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.