Solved

multi-part identifier error?

Posted on 2015-01-29
10
134 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
  • 4
  • 3
  • 3
10 Comments
 
LVL 33

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
 
LVL 33

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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 33

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 33

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

758 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

21 Experts available now in Live!

Get 1:1 Help Now