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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
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 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.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

929 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

10 Experts available now in Live!

Get 1:1 Help Now