Did this work when you tried it?
ExecuteSQL ( "select sum(L.POInvAmt) from Ledger L where BudgetCategory= ?and subcategory =? ";"";"";BudgetCat , SubCat)
Appears to be correct syntax provided that BudgetCategory and subcategory are both fields in Ledger and your "context" for this calculation is the table where BudgetCat and SubCat are defined as global variables. (Otherwise, you need a TableOcurrence::FieldName type reference for the two optional parameters at the end.)