[Solved] Error in query using where clause of split database

Creating tables and queries
Post Reply
syp1977
Posts: 31
Joined: Thu Apr 08, 2021 7:58 pm

[Solved] Error in query using where clause of split database

Post by syp1977 »

My question is in continuation with my previous post.
Let me clarify that I have upgraded my hsqldb to 2.5.1.
I have modified the query to filter the remaining stock which is less than or equal to zero for understanding entry errors. Following is the code:

Code: Select all

select
   a."Material_ID", a."Material_Name", a."Received_Qty", coalesce(b."Qty_Utilized", 0) "Qty_Utilized",
   a."Received_Qty" - coalesce(b."Qty_Utilized", 0) "RemainingStock"
from
(
   select  "Material_ID", "Material_Name", sum("Received_Qty") as "Received_Qty"
   from "Table1"
   group by "Material_ID", "Material_Name"
) a
left join
(
   select  "Material_ID", sum("Qty_Utilized") as "Qty_Utilized"
   from "Table2"
   group by "Material_ID"
) b
   on a."Material_ID" = b."Material_ID" where "RemainingStock" <= 0, Order by "Material_ID"
I am getting following error:
The data content could not be loaded. user lacks privilege or object not found: RemainingStock in statement
Thanking you in advance.
Last edited by syp1977 on Tue Feb 22, 2022 12:14 pm, edited 1 time in total.
OpenOffice 4.1.2 on Windows 10
User avatar
Villeroy
Volunteer
Posts: 31324
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Error in query for using where clause in split database

Post by Villeroy »

Wrap all the names in double-quotes including alias names such as "a".
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
chrisb
Posts: 300
Joined: Mon Jun 07, 2010 4:16 pm

Re: Error in query for using where clause in split database

Post by chrisb »

this is one of the conflicts between hsqldb 1.x and hsqldb 2.x.

"RemainingStock" is the alias for a calculated value generated for final output i.e. not within a sub-query.
it cannot be referenced by the WHERE clause.

use:

Code: Select all

where a."Received_Qty" - coalesce(b."Qty_Utilized", 0) <= 0
 Edit: just noticed the comma before the ORDER BY clause, DELETE IT. 
open office 4.1.14 & LibreOffice 6.4.4.2 x64 using HSQL 1.8.0.10 (Embedded) and HSQL 2.6.0 (Split) on Windows 10
syp1977
Posts: 31
Joined: Thu Apr 08, 2021 7:58 pm

Re: Error in query for using where clause in split database

Post by syp1977 »

Thanks a lot.. It worked
OpenOffice 4.1.2 on Windows 10
Post Reply