[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 179
  • Last Modified:

How to use code the SQL for setting two fields(columns) to NULL in Access?

I have the following code to set a field to NULL in my database which works great.

Sub Clear_Columns()
        conn.Open()
        strSQL = "UPDATE FirstShift_Checklist SET Checked_By = NULL"
         Dim cmd As New OleDbCommand(strSQL, conn)
        cmd.ExecuteNonQuery()
        conn.Close()
    End Sub

But, I need to clear out two fields, how would I do that with one SQL UPDATE statement or do I have to use two SQL UPDATE statements??

I tried this:
strSQL = "UPDATE FirstShift_Checklist SET Checked_By = NULL AND Comments = NULL"

this didn't work.

I tried this also:
strSQL = "UPDATE FirstShift_Checklist SET Checked_By = NULL AND SET Comments = NULL"

this gave me a SQL syntax error.

Any ideas??

thanks

I need to set the following to fields to NULL:
Checked_By
Comments
0
Richard Kreidl
Asked:
Richard Kreidl
1 Solution
 
AvelanCommented:
Try this:

"UPDATE FirstShift_Checklist SET Checked_By = NULL, Comments = NULL"

-Avelan
0
 
Richard KreidlSoftware DeveloperAuthor Commented:
thanks!! It worked.
0
 
shrikantssCommented:
I YOur COde
strSQL = "UPDATE FirstShift_Checklist SET Checked_By = NULL AND SET Comments = NULL"
actually the you are using keyword SET twice
or You can write it like
strSQL = "UPDATE FirstShift_Checklist SET Checked_By = NULL ,Comments = NULL"
or
strSQL  = "UPDATE FirstShift_Checklist SET Checked_By = NULL  AND Comments = NULL"
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now