Solved

multi-part identifier error?

Posted on 2015-01-29
10
152 Views
Last Modified: 2015-01-29
I have 2 different tables in the same database.
tblInvoice
tblTemp

The tables are similar:
tblInvoice
      ID,
      UserID,
      Date,
      Volume

tblTemp
      ID,
      UserID,
      Date,
      AdjVolume

where the userID and Date are the same UserID and Date from each table, with



UPDATE tblInvoice
SET tblGasInvoice.[ Volume] = tblTemp.Volume
WHERE tblTemp.UserID = tblInvoice.UserID AND
tblTemp.Date = tblInvoice.Date

I get the following error:
Msg 4104,
The multi-part identifier "tblTemp.UserID" could not be bound.
Msg 4104,
The multi-part identifier "tblTemp.Date" could not be bound.

I wrote out the code using intellisense in SMS to make sure there were no typos in the naming

Any ideas?
Thanks for your help!
0
Comment
Question by:ITMikeK
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
10 Comments
 
LVL 34

Assisted Solution

by:Mike Eghtebas
Mike Eghtebas earned 100 total points
ID: 40577985
UPDATE tblInvoice
SET tblGasInvoice.[Volume] = tblTemp.AdjVolume
WHERE tblTemp.UserID = tblInvoice.UserID AND
tblTemp.Date = tblInvoice.Date

There was an extra space in [ Volume]
tblTemp doesn't have [Volume], it has AdjVolume

Also, you may have to change Date to [Date]
0
 

Author Comment

by:ITMikeK
ID: 40577995
Sorry my mistake in drafting the question.
tblGasInvoice.[Volume] = tblTemp.AdjVolume    is what I should have typed!
0
 
LVL 12

Expert Comment

by:Habib Pourfard
ID: 40577998
You need to include all needed tables in the from clause to be able to use their column name. something like the following code ( I am not sure about the logic as I don't know table structure of all your tables):

UPDATE tblGasInvoice
SET Volume = t.AdjVolume
FROM tblGasInvoice g
INNER JOIN tblInvoice i ON g.InvoiceID = i.ID
INNER JOIN tblTemp t ON t.UserID = i.UserID AND t.[Date] = i.[Date]

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40578000
UPDATE tblGasInvoice
SET tblGasInvoice.[Volume] = tblTemp.AdjVolume
WHERE tblGasInvoice.UserID = tblTemp.UserID AND
tblGasInvoice.[Date] = tblTemp.[Date]
0
 

Author Comment

by:ITMikeK
ID: 40578008
Repost with correction... thank for the eyes eghtbas!
I have 2 different tables in the same database.
 tblInvoice
 tblTemp

 The tables are similar:
 tblInvoice
       ID,
       UserID,
       Date,
       Volume

 tblTemp
       ID,
       UserID,
       Date,
       AdjVolume

 where the userID and Date are the same UserID and Date from each table, with



 UPDATE tblInvoice
 SET tblInvoice.[Volume] = tblTemp.AdjVolume
 WHERE tblTemp.UserID = tblInvoice.UserID AND
 tblTemp.Date = tblInvoice.Date

 I get the following error:
 Msg 4104,
 The multi-part identifier "tblTemp.UserID" could not be bound.
 Msg 4104,
 The multi-part identifier "tblTemp.Date" could not be bound.

 I wrote out the code using intellisense in SMS to make sure there were no typos in the naming

 Any ideas?
 Thanks for your help!
0
 
LVL 12

Expert Comment

by:Habib Pourfard
ID: 40578019
As I said in the previous comment From clause is missing, you need to include tblInvoice, tblGasInvoice and tblTemp in the from clause and relate them together.

Also you need to write UPDATE tblGasInvoice instead of UPDATE tblInvoice if you want to update it's column.
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40578035
UPDATE tblInvoice as inv
  Inner join tblTemp as tmp
  on (inv.UserID = tmp.UserID AND inv.Date = tmp.Date)
  inner join tblGasInvoice as gas
  on inv.UserID = gas.UserID
 SET inv.[Volume] = tmp.AdjVolume
0
 

Author Comment

by:ITMikeK
ID: 40578091
There is no tblGasInvoice, that was a mistake I tried to correct a couple of posts ago...
 tblInvoice
        ID,
        UserID,
        Date,
        Volume

  tblTemp
        ID,
        UserID,
        Date,
        AdjVolume

  where the userID and Date are the same UserID and Date from each table, with



  UPDATE tblInvoice
  SET tblInvoice.[Volume] = tblTemp.AdjVolume
  WHERE tblTemp.UserID = tblInvoice.UserID AND
  tblTemp.Date = tblInvoice.Date

Sorry about the confusion...I really messed up the original post!
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40578095
UPDATE tblInvoice as inv
  Inner join tblTemp as tmp
  on (inv.UserID = tmp.UserID AND inv.[Date] = tmp.[Date])
 SET inv.[Volume] = tmp.AdjVolume
0
 
LVL 12

Accepted Solution

by:
Habib Pourfard earned 400 total points
ID: 40578101
UPDATE tblInvoice
SET Volume = t.AdjVolume
FROM tblInvoice i
INNER JOIN tblTemp t ON t.UserID = i.UserID AND t.[Date] = i.[Date]

Open in new window

0

Featured Post

Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

695 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