Dim dSql As SQL
dim Cursor1 as Cursor
dSql.ExecQuery("SELECT * FROM hours WHERE ROWID = " & id)
Cursor1.Position=0
If Cursor1.GetString("FIELDNAME") =Null Then
dSql.ExecNonQuery2("UPDATE hours SET FIELDNAME= ? WHERE ROWID =?",Array As Object("dgoss",id))
End If
Dim dSql As SQL
dim Cursor1 as Cursor
dSql.ExecQuery("SELECT * FROM hours WHERE ROWID = " & id)
Cursor1.Position=0
If Cursor1.GetString("FIELDNAME") =Null Then
dSql.ExecNonQuery2("UPDATE hours SET FIELDNAME= ? WHERE ROWID =?",Array As Object("dgoss",id))
End If
dSql.ExecNonQuery2("UPDATE hours SET my_field_name = ? WHERE isnull(my_field_name,'')='' AND rowid = ?", ArrayAs Object("XXXX", id))
To check in a Where if is null you can use ISNULL or COLAESCE statement.
(For more info about ISNULL or COALESCE search at Google: TRANSACT SQL COALESCE
or TRANSACT SQL ISNULL)
ISNULL(FIELD,valuex)
if FIELD is NULL, then statement returns valuex as Value.
So you can also use this:
B4X:
dSql.ExecNonQuery2("UPDATE hours SET my_field_name =ISNULL(my_field_name, ?) WHERE rowid = ?", ArrayAs Object("XXXX", id))
'Here if my_field_name not is null, it keeps its value,
'if my_field_name is null, "XXXX" is set as new value.
Also you can set all in a string
B4X:
Dim SQLString as String=""
Dim StrNewValue as String="XXXX"
SQLString="UPDATE hours SET my_field_name =ISNULL(my_field_name, '" & StrNewValue & "' ) WHERE rowid = " & id.ToString
'SQLString contents looks like this (for example if id=21):
'"UPDATE hours SET my_field_name =ISNULL(my_field_name, 'XXXX' ) WHERE rowid = 21"
dSql.ExecNonQuery(SQLString)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.