question

Ayman avatar image
Ayman asked

SQL syntax error: Multi-part identifier could not be bound.

The error message I get is as follows: Msg 4104, Level 16, State 1, Line 3 The multi-part identifier "t.CustID" could not be bound. Msg 4104, Level 16, State 1, Line 4 The multi-part identifier "t.InvoiceID" could not be bound. Msg 4104, Level 16, State 1, Line 5 The multi-part identifier "t.Date" could not be bound. Msg 4104, Level 16, State 1, Line 6 The multi-part identifier "t.S_Type" could not be bound. The query: select seq = row_number() over ( partition by t.CustID order by t.InvoiceID, t.Date, CASE WHEN t.S_Type = 'Receipt Voucher' THEN 1 ELSE 2 END ) ; WITH cte AS ( SELECT CustID, [InvoiceID], S_Type, DATE, Debit, Credit, seq = row_number() OVER ( ORDER BY InvoiceID, DATE, CASE WHEN S_Type = 'Receipt Voucher' THEN 1 ELSE 2 END ) FROM Statement ) SELECT c.[InvoiceID], c.S_Type AS Type, c.DATE, c.Debit, c.Credit, b.Balance FROM cte c CROSS APPLY ( SELECT Balance = SUM(Debit) - SUM(Credit) FROM cte AS x WHERE x.CustID = c.CustID AND x.seq <= c.seq ) b WHERE c.CustID = '48' AND DATE BETWEEN '2015-01-01' AND '2016-01-01' ORDER BY seq
sql-server-2008sqlsql-server-2008-r2tsql
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Grant Fritchey avatar image Grant Fritchey ♦♦ commented ·
You have some good answers below. This web site runs by you voting and marking the best answers. For each helpful answer below, indicate this by clicking on the thumbs up symbol next to those answers. If any one answer lead to a solution, indicate this by clicking on the check mark next to that answer. This helps indicate your solution for anyone else with the same question.
0 Likes 0 ·
javed79 avatar image
javed79 answered
You are using an alias 't', but where is the reference table/query for t?
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Venkataraman avatar image
Venkataraman answered
select seq = row_number() over ( partition by t.CustID order by t.InvoiceID, t.Date, CASE WHEN t.S_Type = 'Receipt Voucher' THEN 1 ELSE 2 END ) ; What does t refer to ? You are getting error due to this.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Abdul.Wahab avatar image
Abdul.Wahab answered
Hello every one. I need your help. My query is running ok in SQL 2005 but when I am tring to run same query in sql 2014 error : The multi-part identifier "lh.loadlstno" could not be bound. problem portion is : lh.loadlstno, lh.toplant, s1.statuskurzbez this portion is only select Null statement for business reason. Any suggesion ? SELECT r.nextstatusdateout, r.po, r.poline, a.wo, a.plandate, r.item, r.status, s.statusbez, a.transferno, r.nextstatusdateraw, d.suppliername AS Lieferant, NULL AS LoadLstNo, NULL AS ToPlant, NULL AS StatusKurzBez, Sum ( r.net) AS SumNet, Sum (a.qty) AS SumQty, Count (a.identno) AS NoOfAllocs, Count (r.identno) AS NoOfRolls FROM rmrolls r INNER JOIN artikelstamm i ON r.item = i.artikelnr INNER JOIN rmdelivery d ON r.deliveryno = d.deliveryno INNER JOIN rmallocation a ON r.identno = a.identno INNER JOIN stati s ON r.status = s.status WHERE r.nextstatusdateraw IS NOT NULL AND r.status >= 34 AND r.status < 40 GROUP BY r.nextstatusdateout, r.po, r.poline, a.wo, a.plandate, r.item, r.status, s.statusbez, a.transferno, r.nextstatusdateraw, d.suppliername ORDER BY r.nextstatusdateout, a.wo, r.item, r.po, r.poline, a.plandate, r.status, s.statusbez, a.transferno, r.nextstatusdateraw, d.suppliername, lh.loadlstno, lh.toplant, s1.statuskurzbez
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ThomasRushton avatar image ThomasRushton ♦♦ commented ·
Suggestion: ask this as a new question - you'll get more people taking an interest.
0 Likes 0 ·
ThomasRushton avatar image ThomasRushton ♦♦ commented ·
However... looking at your query, you don't appear to be selecting anything from a table named or aliased "lh". Hence SQL 2014 very properly raising an error.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.