Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 3rd, 2007, 05:04 AM
Friend of Wrox
 
Join Date: Jan 2006
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
 
Old August 3rd, 2007, 08:57 PM
Friend of Wrox
 
Join Date: Oct 2006
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





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





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