[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

multi-part identifier error?

Posted on 2015-01-29
10
Medium Priority
?
159 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 400 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 1600 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

656 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