help required in simple select query

  • SELECT Vw_Final_Inventory_Report_1.*,

    (select sum(Dqtyin) - sum(Dqtyout) from Tb_Item_Cost_Ledger where itemid = Vw_Final_Inventory_Report_1.coa_id and VDate < '2009/01/01') as ClosingBalance

    FROM Vw_Final_Inventory_Report_1

    this query works fine

    but when i try to input where clause it gives error as following

    SELECT Vw_Final_Inventory_Report_1.*,

    (select sum(Dqtyin) - sum(Dqtyout) from Tb_Item_Cost_Ledger where itemid = Vw_Final_Inventory_Report_1.coa_id and VDate < '2009/01/01') as ClosingBalance

    FROM Vw_Final_Inventory_Report_1

    where (ClosingBalance = 0 )

  • You can not use derived column names in the WHERE clause.

    Try following query:

    SELECT Vw_Final_Inventory_Report_1.*

    ,(sum(Dqtyin) - sum(Dqtyout)) AS ClosingBalance

    FROM Vw_Final_Inventory_Report_1 vw

    INNER JOIN Tb_Item_Cost_Ledger tb

    ON tb.itemid = vw.Vw_Final_Inventory_Report_1.coa_id

    WHERE VDate < '2009/01/01'

    AND (sum(Dqtyin) - sum(Dqtyout)) = 0

    -Vikas Bindra

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply