Solved

multi-part identifier error?

Posted on 2015-01-29
10
146 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

730 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