D dgoss Member Licensed User Longtime User Aug 30, 2015 #1 I am using the following statement to read database:- dSql.ExecQuery("SELECT * FROM hours WHERE rowid = " & id) the table has about 13 fields, how do I check if a field is NULL and insert some other text thx in advance
I am using the following statement to read database:- dSql.ExecQuery("SELECT * FROM hours WHERE rowid = " & id) the table has about 13 fields, how do I check if a field is NULL and insert some other text thx in advance
M Mahares Expert Licensed User Longtime User Aug 30, 2015 #2 Something like this: Code: Copy 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 Upvote 0
Something like this: Code: Copy 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
D dgoss Member Licensed User Longtime User Aug 30, 2015 #3 Mahares said: Something like this: Code: Copy 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 Click to expand... thx mahares works for me Upvote 0
Mahares said: Something like this: Code: Copy 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 Click to expand... thx mahares works for me
J JohnK Active Member Licensed User Longtime User Aug 30, 2015 #4 dgoss said: I am using the following statement to read database:- dSql.ExecQuery("SELECT * FROM hours WHERE rowid = " & id) the table has about 13 fields, how do I check if a field is NULL and insert some other text Click to expand... I would do the whole process in SQL in a single line of code eg: Code: Copy dSql.ExecNonQuery2("UPDATE hours SET my_field_name = ? WHERE my_field_name IS NULL AND rowid = ?", Array As Object("XXXX", id)) Upvote 0
dgoss said: I am using the following statement to read database:- dSql.ExecQuery("SELECT * FROM hours WHERE rowid = " & id) the table has about 13 fields, how do I check if a field is NULL and insert some other text Click to expand... I would do the whole process in SQL in a single line of code eg: Code: Copy dSql.ExecNonQuery2("UPDATE hours SET my_field_name = ? WHERE my_field_name IS NULL AND rowid = ?", Array As Object("XXXX", id))
jsanchezc Member Licensed User Longtime User Aug 30, 2015 #5 JohnK said: I would do the whole process in SQL in a single line of code eg: Code: Copy dSql.ExecNonQuery2("UPDATE hours SET my_field_name = ? WHERE my_field_name IS NULL AND rowid = ?", Array As Object("XXXX", id)) Click to expand... Code: Copy 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: Code: Copy 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 Code: Copy 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) Hope this help Last edited: Aug 30, 2015 Upvote 0
JohnK said: I would do the whole process in SQL in a single line of code eg: Code: Copy dSql.ExecNonQuery2("UPDATE hours SET my_field_name = ? WHERE my_field_name IS NULL AND rowid = ?", Array As Object("XXXX", id)) Click to expand... Code: Copy 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: Code: Copy 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 Code: Copy 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) Hope this help
M Mahares Expert Licensed User Longtime User Aug 30, 2015 #6 jsanchezc said: my_field_name =ISNULL(my_field_name, '" & StrNewValue & "' ) Click to expand... There is no ISNULL function in SQLite. It should be IFNULL. Last edited: Aug 30, 2015 Upvote 0
jsanchezc said: my_field_name =ISNULL(my_field_name, '" & StrNewValue & "' ) Click to expand... There is no ISNULL function in SQLite. It should be IFNULL.
jsanchezc Member Licensed User Longtime User Aug 31, 2015 #7 Mahares said: There is no ISNULL function in SQLite. It should be IFNULL. Click to expand... Ok, i see SQL and i understood SQL Server (MSSQL) Upvote 0
Mahares said: There is no ISNULL function in SQLite. It should be IFNULL. Click to expand... Ok, i see SQL and i understood SQL Server (MSSQL)
D dgoss Member Licensed User Longtime User Sep 3, 2015 #8 thx guys sorry for delay in replying but i'm doing this on the road, I used Mahares example it works for me with what i'm doing. Upvote 0
thx guys sorry for delay in replying but i'm doing this on the road, I used Mahares example it works for me with what i'm doing.