Hello,
I have a query that is to be used for 4 different options. The parameters differ depending on the option. The problem is that sometimes NULL is to be entered in different fields.
So far there have therefore been 4 different queries.
Here is a simplified example:
Since NULL can occur in different variants of State and Invoice, the whole thing becomes quite confusing.
It would be nice if there was only one query instead:
Unfortunately, I cannot change the table and set the default value to NULL.
Is there a better solution?
Thanks in advance.
I have a query that is to be used for 4 different options. The parameters differ depending on the option. The problem is that sometimes NULL is to be entered in different fields.
So far there have therefore been 4 different queries.
Here is a simplified example:
B4X:
Select condition
Case 0
SQL.ExecNonQuery2("INSERT INTO Test(CustomerID, State, Invoice, Date) VALUES (?, NULL, ?, ?)", Array As String(NewID, Invoice, DateTime.Date(DateTime.Now))) 'State = NULL, Invoice = 1
Case 1
SQL.ExecNonQuery2("INSERT INTO Test(CustomerID, State, Invoice, Date) VALUES (?, ?, NULL, ?)", Array As String(NewID, State, DateTime.Date(DateTime.Now))) ' State = 0, Invoice = NULL
Case 2
SQL.ExecNonQuery2("INSERT INTO Test(CustomerID, State, Invoice, Date) VALUES (?, ?, ?, ?)", Array As String(NewID, State, Invoice, DateTime.Date(DateTime.Now))) ' State = 1, Invoice = 0
End Select
It would be nice if there was only one query instead:
B4X:
Dim State As Object = NULL
Dim Invoice As Object = NULL
If Condition = 0 Then Invoice = 1
SQL.ExecNonQuery2("INSERT INTO Test(CustomerID, State, Invoice, Date) VALUES (?, ?, ?, ?)", Array As String(NewID, State, Invoice, DateTime.Date(DateTime.Now)))
Is there a better solution?
Thanks in advance.