Solved

multi-part identifier error?

Posted on 2015-01-29
10
138 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
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

948 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

22 Experts available now in Live!

Get 1:1 Help Now