Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

T-SQL UPDATE error?

Posted on 2004-10-07
7
Medium Priority
?
758 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
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
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 2000 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

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
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.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

916 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