Solved

Multi-part identifier could not be bound- SQL update queries based off of matching variables in two tables - URGENT

Posted on 2007-03-31
4
4,933 Views
Last Modified: 2012-06-22
I'm trying to update a field in table 1 (pricing.mod_type)to = a field in table 2 (archive.pendingmod),  but I only want to select the most recent of [archive.pendingmod] based off of a incrementing key field. I am matching the two tables based on a master number, which appears multiple times in the archive (one record per different pendingmod, but i just want the most recent, hence selecting the max of the key). I am also matching this where archive.contractlistprice=pricing.contractlistprice and only updating those where pricing.contract='xxxxxxxxx' (obscured for company privacy)

Here is my code:

update pricing
set [pricing].[mod_type]=[archive].[pendingmod]
      select max([archive].[key])
      from [archive]
      where [pricing].[immixmasterno]=[archive].[immixmasterno]
            and [pricing].[contractlistprice]=[archive].[contractlistprice]
            and [pricing].[contract]='XXXXXXj'

And here are my errors:
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "archive.pendingmod" could not be bound.
Msg 4104, Level 16, State 1, Line 3
The multi-part identifier "pricing.immixmasterno" could not be bound.
Msg 4104, Level 16, State 1, Line 3
The multi-part identifier "pricing.contractlistprice" could not be bound.
Msg 4104, Level 16, State 1, Line 3
The multi-part identifier "pricing.contract" could not be bound.


0
Comment
Question by:immixGroup
  • 3
4 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 18828889
Something like this:

update      p
set            mod_type = a.pendingmod
from      pricing p
            Inner Join (
                        Select      Top 1
                                    pendingmod,
                                    immixmasterno,
                                    contractlistprice
                        From      archive
                        Order By
                                    [key] DESC) a On p.immixmasterno = a.immixmasterno
                              and p.contractlistprice = a.contractlistprice
Where      p.[contract]='XXXXXXj'
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 18828898
On second thoughts, this may be what you need:

update      p
set            mod_type =       (Select      Top 1
                                          pendingmod,
                              From      archive
                              Where      immixmasterno = p.immixmasterno
                                          and contractlistprice = p.contractlistprice
                              Order By
                                          [key] DESC
from      pricing p
Where      [contract]='XXXXXXj'
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 total points
ID: 18828902
Oops, let's try that again:

update      p
set            mod_type =       (Select      Top 1
                                          pendingmod
                              From      archive
                              Where      immixmasterno = p.immixmasterno
                                          and contractlistprice = p.contractlistprice
                              Order By
                                          [key] DESC)
from      pricing p
Where      [contract]='XXXXXXj'
0
 

Author Comment

by:immixGroup
ID: 18832430
AC, thanks for the response, sorry I didn't award points sooner. I might have a similar help request with the same reward in a few minutes if you're interested. Thanks again for the help!
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.

Join & Write a Comment

Suggested Solutions

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
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…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

747 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

12 Experts available now in Live!

Get 1:1 Help Now