Forum

This content is now out of date.

Visit Our Community

SQL statement invalid. Unknown Column

Hi there,

I am trying to edit a SQL view, but I keep receiving an error every time I try to validate the SQL or move on to the next step.

The SQL in question is:
SELECT TRB_TRIP_BOOKING_ID as 'Trip Booking ID', TRB_TRAVEL_DATE as 'Travel Date', TRB_PRICE AS 'Trip Price', MAX(TBS_BOOKED_PASSENGERS) as 'Booked Passengers',MAX(ifnull(TBS_BOARDED_PASSENGERS,0)) as 'Boarded Passengers'
FROM trb_table
INNER JOIN tbs_table
ON TRB_TRIP_BOOKING_ID = TBS_TRIP_BOOKING_ID
AND (TRB_MEMBER_PASSPORT_COMPONENT_ID IS NULL OR TRB_MEMBER_PASSPORT_COMPONENT_ID = 0)
AND TRB_STATUS = 'CO'
GROUP BY
TRB_TRIP_BOOKING_ID,
TRB_TRAVEL_DATE,
TRB_PRICE

I have run the exact query on the database directly and it works perfectly fine.

The error message I get is:
SQL statement is invalid.
The error message returned from the database was:
Unknown column 'TRB_TRIP_BOOKING_ID' in 'field list'

I would appreciate some help on this matter.

Thank you.
Hi,

I'm not sure why the query is working when you're running it against your DB as it doesn't look like you are specifying the tables in your query .

E.g.
SELECT .TRB_TRIP_BOOKING_ID as 'Trip Booking ID',
.TRB_TRAVEL_DATE....

Can you try including the table names in your query and let me know how it goes?

Regards,
David



I have tried adding the table name qualifiers and it still comes up with the same error.

I should mention that I am simply adding the
MAX(ifnull(TBS_BOARDED_PASSENGERS,0)) as 'Boarded Passengers'
column to the view.

The unedited version of the view (which is the same as this view, minus the new column) functions perfectly.

It seems odd that only now the problem appears.

What could be happening here?
Hi,

It is odd that the original view works, and simply adding an extra column would make it complain about not finding columns.

Can you please email across (or past in the forum) both view SQL's so we can see if anything else sticks out?

Also, did you add table identifiers for the entire query?

Thanks,
David