Solved

T-SQL UPDATE error?

Posted on 2004-10-07
7
753 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
connection to SQL 2012 error in windows 10 18 49
SQL Server 2012 to SQL Server 2016 24 57
invoke-sqlcmd help 5 34
Sql server query 8 21
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

752 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