Solved

T-SQL UPDATE error?

Posted on 2004-10-07
7
749 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to shrink a transaction log file down to a reasonable size.

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now