Brian's Blog

items I see across my tribes

SQL Server – Check for NULL/Empty

June 09
by briancarter 9. June 2009 22:48

Don’t forget, in SQL Server null is never equal to anything.  So use IS NULL to check for columns with NULL.

UPDATE Stage_Enrollment
  SET [RECD-ERROR-CODE]='PO# INVL'
  where ([REC-TYPE] = 'D') AND ([CONT-NUM] IS NULL
    OR LTRIM(RTRIM([CONT-NUM])) = '')

Bonus: boolean test if string is not a date: IsDate([CANCEL-EFF-DATE]) = 0 ... returns 1 if valid.

Bonus: sql server full trim, LTRIM(RTRIM([TOTAL-REFUND])) 

Bonus: when updating, add column value based on another column: (SELECT CASE WHEN RECD_ERROR_CODE IS NULL THEN 'R' ELSE 'N' END) AS CANCEL_FLAG

Categories: Development

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading




 Questions or Feedback, my contact information is located on my About page.


The opinions, thoughts, and comments made in these blog posts are solely my own (unless otherwise stated). They do not reflect the opinions, thoughts or practices of my employer, my universities, my family, or anyone else. Also, I retain the right to change my mind about anything I publish here without having to go back and edit posts that occurred in the past. 

These are my opinions, or just as likely, someone else's opinions that I leveraged for my own.