• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQL query problem with MySQL

 
Zein Nunna
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I have a table called 'USER', I've just added a new colum (attribute) called regDate (type varchar).

Now all the existing records have regDate set to NULL, what I want to do is change all the NULL values to some date. My query is as follow

UPDATE USER SET regDate = '19/07/2007 1.11pm' WHERE regDate = NULL;

This doesn't unfortunatley update all the NULL columns with the date.

I suspect it's due to me using regDate twice in the query, but I cant see how else I could update all the columns.
So my questions, is my query correct? Is there a better way of writing this query so I can update the relevant columns?

I'm using MySQL db.

Thanks for your thoughts,
Regards
Zein
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know MySQL very well, but usually in SQL a field is null but is not equal to null. Try:
 
Zein Nunna
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fabulous Paul, works like a charm.

Thank you very much. Much appreciated.
Zein
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic