Solved

T-SQL UPDATE error?

Posted on 2004-10-07
7
750 Views
Last Modified: 2012-08-14
My code:

UPDATE [ACCTG].[dbo].[Co$AgileItem]
SET [Mfg Name]=[ACCTG].[dbo].[Co$AgileOra].[Mfg Name]

and I get the following error?

Server: Msg 107, Level 16, State 3, Line 1
The column prefix 'ACCTG.dbo.Co$AgileOra' does not match with a table name or alias name used in the query.

What gives????
0
Comment
Question by:mtnbuzz
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 21

Expert Comment

by:mastoo
ID: 12251428
UPDATE [ACCTG].[dbo].[Co$AgileItem]
SET [Mfg Name]=[ACCTG].[dbo].[Co$AgileOra].[Mfg Name]
FROM [ACCTG].[dbo].[Co$AgileItem], [ACCTG].[dbo].[Co$AgileOra]
WHERE PutSomeKindOfJoinClauseHere
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 12251434
UPDATE [ACCTG].[dbo].[Co$AgileItem]   <--- this is the table to be updated
SET [Mfg Name]=[ACCTG].[dbo].[Co$AgileOra].[Mfg Name]  <--- doesn't specify the same table name

and you haven't provided a From clause to specify the relationship
between the rows in [Co$AgileItem]
and [Co$AgileOra]

what are you actually trying to do?
0
 

Author Comment

by:mtnbuzz
ID: 12251493
Create on UPDATE stmt to update 2 columns [Mfg] and [Mfg Part Number] from table [ACCTG].[dbo].[Co$AgileOra].[Mfg Name] to [ACCTG].[dbo].[Co$AgileItem] with the exact same data just missing the Mfg info.


[ACCTG].[dbo].[Co$AgileOra]                   [ACCTG].[dbo].[Co$AgileItem]
[No.]   09-0200-001                                 [No.] 09-0200-001
[Descrip] Test                                         [Descrip] Test
[Mfg] Jones                                             [Mfg] NULL
[Mfg Part Number] 123                             [Mfg Part Number] NULL

0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 50

Expert Comment

by:Lowfatspread
ID: 12251576
update [Acctg].[dbo].[Co$AgileItem]
  set A.[Mfg] = B.[Mfg]
       ,A.[Mfg Part Number]=B.[Mfg Part Number]
 from [Acctg].[dbo].[Co$AgileItem] as A
 Inner Join [Acctg].[dbo].[Co$AgileOra] as B
    on A.[No.] = b.[No.]
 

assuming that [No.] is the primary key of both tables...


0
 

Author Comment

by:mtnbuzz
ID: 12251671
Ran the code:

update [acctg].[dbo].[co$AgileItem]
  set [acctg].[dbo].[co$AgileItem].[Mfg] = [acctg].[dbo].[co$AgileOra].[Mfg]
       ,[acctg].[dbo].[co$AgileItem].[Mfg Part Number] = [acctg].[dbo].[co$AgileOra].[Mfg Part Number]
 from [acctg].[dbo].[co$AgileItem] as A
 Inner Join [acctg].[dbo].[co$AgileOra] as B
    on A.[No.] = b.[No.]
 
and got this error

Server: Msg 107, Level 16, State 3, Line 1
The column prefix 'acctg.dbo.co$AgileOra' does not match with a table name or alias name used in the query.
Server: Msg 107, Level 16, State 1, Line 1
The column prefix 'acctg.dbo.co$AgileOra' does not match with a table name or alias name used in the query.

But I do have a table named acctg.dbo.co$AgileOra?
0
 
LVL 21

Accepted Solution

by:
mastoo earned 500 total points
ID: 12251884
update [acctg].[dbo].[co$AgileItem]
  set [acctg].[dbo].[co$AgileItem].[Mfg] = [acctg].[dbo].[co$AgileOra].[Mfg]
       ,[acctg].[dbo].[co$AgileItem].[Mfg Part Number] = [acctg].[dbo].[co$AgileOra].[Mfg Part Number]
 from [acctg].[dbo].[co$AgileItem]
 Inner Join [acctg].[dbo].[co$AgileOra]
    on [acctg].[dbo].[co$AgileItem].[No.] = [acctg].[dbo].[co$AgileOra].[No.]
0
 
LVL 15

Expert Comment

by:jdlambert1
ID: 12251909
You're defining aliases, then not using them except in the ON clause. This will do it:

update A
  set [Mfg] = B.[Mfg]
       , [Mfg Part Number] = B.[Mfg Part Number]
 from [acctg].[dbo].[co$AgileItem] as A
 Inner Join [acctg].[dbo].[co$AgileOra] as B
    on A.[No.] = b.[No.]
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

803 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