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,936 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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.net and sql server 4 36
Deal with apostrophe in stored procedures 8 43
Create snapshot on MSSQL 2012 3 21
MS SQL Server COnditional Where statement 7 64
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
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 set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

832 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