cSQL = "SELECT all Stock.id as Id, Stock.record_type as Record_Type, sum(Stock_Take.qty) as Qty FROM Stock_take JOIN Stock ON Stock_Take.id = Stock.id GROUP BY Stock.id UNION ALL SELECT Stock.id, Stock.Record_Type, 0 FROM Stock where Stock.id not in (select DISTINCT Stock_Take.id from stock_take) order by record_type, id"
dbSQL.ExecQueryAsync("SQLindex",cSQL,Null)
Sub SQLindex_QueryComplete(Success As Boolean, curResult As Cursor)
If Success Then
Dim List_Stock As List
Dim cID, cRecord_Type, cQty As String
Dim cStock_item As String
List_Stock.Initialize
'
For I = 0 To curResult.RowCount-1
curResult.Position=I
cID = curResult.GetString("Id")
cRecord_Type = curResult.GetString("Record_Type")
cQty = curResult.GetString("Qty")
cStock_item = cID & "," & cRecord_Type & "," & cQty & ","
List_Stock.add(cStock_item)
Next
File.WriteList(tcFolder,tcFile,List_Stock)
Else
Log(LastException)
End If
curResult.Close
End Sub