How to use NULL or empty string in SQL

前端 未结 16 1687
悲&欢浪女
悲&欢浪女 2020-12-23 20:20

I would like to know how to use NULL and an empty string at the same time in a WHERE clause in SQL Server. I need to find records that have either null values o

16条回答
  •  天命终不由人
    2020-12-23 20:45

    To find rows where col is NULL, empty string or whitespace (spaces, tabs):

    SELECT *
    FROM table
    WHERE ISNULL(LTRIM(RTRIM(col)),'')=''
    

    To find rows where col is NOT NULL, empty string or whitespace (spaces, tabs):

    SELECT *
    FROM table
    WHERE ISNULL(LTRIM(RTRIM(col)),'')<>''
    

提交回复
热议问题