Anju Maharjan
Anju Maharjan

Reputation: 51

Invalid Column Name SQL Server; even though the column is present

I have a code of around 813 lines. The code is executed through excel macro automatically. There is an Error:

Executing the query " Select A.LoanKey AS LoanKey, MAX(B.LoanKey)..."
failed with the following error: "Invalid column name 'LoanProductKey'.

This column is used in many places. eg:

SELECT A.*,B.*
from someDatabase.dbo.tableA A
JOIN someDatabase.dbo.tableB B ON A.LoanProductKey = B.LoanProductKey

I have checked and made sure that both tables have that column.

Running the whole code manually doesn't throw any error.

So I am not able to debug the code too.

Upvotes: 0

Views: 661

Answers (2)

Ganeh Gyawali
Ganeh Gyawali

Reputation: 1

In excel write your code within the below function which removes the non-printing characters of your excel test.

= CLEAN (Write your queries here)

Upvotes: 0

Anju Maharjan
Anju Maharjan

Reputation: 51

Thank you, everybody. The problem was with temp table. What happened was, first temp table was created with a single column from someTable. Later though the table was drop and re-created with LoanProductKey column, the query was referring to the first created table. so I changed the name of second temp table. There is no issue now.

Upvotes: 1

Related Questions