Android Question SQLite query: Dates BETWEEN

Declan

Well-Known Member
Licensed User
Longtime User
I have a local SQLite database table.
I am attempting to read rows from this table using:
B4X:
Sub ShowSalesBySalesPerson(MyStart As String, MyEnd As String)
    Dim Query As String
    Query = "SELECT DISTINCT(Sales_Person) As [Sales Person], Store AS [Store], SUM(Units_Sold) As [Units Sold], SUM(Total_Retail) As [Total Retail] FROM sales_end_user WHERE Sale_Date BETWEEN " & MyStart & " AND " & MyEnd & " GROUP BY Sales_Person ORDER BY Store"
    wbvQuery.LoadHtml(ExecuteHtml(SQL1, Query, Null, 0, True))   
    wbvQuery.Visible=True
End Sub

However, when I use the above SQL query, nothing is returned.

If I use:
B4X:
Sub ShowSalesBySalesPerson(MyStart As String, MyEnd As String)
    Dim Query As String
    Query = "SELECT DISTINCT(Sales_Person) As [Sales Person], Store AS [Store], SUM(Units_Sold) As [Units Sold], SUM(Total_Retail) As [Total Retail] FROM sales_end_user GROUP BY Sales_Person ORDER BY Store"
    wbvQuery.LoadHtml(ExecuteHtml(SQL1, Query, Null, 0, True))   
    wbvQuery.Visible=True
End Sub

I receive the data and the WebView is populated.

I do not receive any errors, Log is:
B4X:
LogCat connected to: B4A-Bridge: SP5 SP5
Installing file.
--------- beginning of /dev/log/main
Installing file.
PackageAdded: package:b4a.example
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
ExecuteHtml: SELECT DISTINCT(Sales_Person) As [Sales Person], Store AS [Store], SUM(Units_Sold) As [Units Sold], SUM(Total_Retail) As [Total Retail] FROM sales_end_user WHERE Sale_Date BETWEEN 2016-03-01 AND 2016-03-31 GROUP BY Sales_Person ORDER BY Store
 

elitevenkat

Active Member
Licensed User
Longtime User
you should use ' char as padding for the date values '2016-03-01' or & "'" & datevalue1 & "' and '" & datevalue2 & '''" in the sql query
 
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
you should use ' char as padding for the date values '2016-03-01' or & "'" & datevalue1 & "' and '" & datevalue2 & '''" in the sql query
Thanks
This works:
B4X:
    Query = "SELECT DISTINCT(Sales_Person) As [Sales Person], Store AS [Store], SUM(Units_Sold) As [Units Sold], SUM(Total_Retail) As [Total Retail] FROM sales_end_user WHERE Sale_Date BETWEEN '" & MyStart & "' AND '" & MyEnd & "' GROUP BY Sales_Person ORDER BY Store"
 
Upvote 0
Top