How do I check if a SQL Server text column is empty?

前端 未结 16 1115
粉色の甜心
粉色の甜心 2020-12-07 11:07

I am using SQL Server 2005. I have a table with a text column and I have many rows in the table where the value of this column is not null, but it is empty. Trying to comp

相关标签:
16条回答
  • 2020-12-07 11:46

    Use DATALENGTH method, for example:

    SELECT length = DATALENGTH(myField)
    FROM myTABLE
    
    0 讨论(0)
  • 2020-12-07 11:47
    where datalength(mytextfield)=0
    
    0 讨论(0)
  • 2020-12-07 11:47
    SELECT * FROM TABLE
    WHERE ISNULL(FIELD, '')=''
    
    0 讨论(0)
  • 2020-12-07 11:48

    To get only empty values (and not null values):

    SELECT * FROM myTable WHERE myColumn = ''
    

    To get both null and empty values:

    SELECT * FROM myTable WHERE myColumn IS NULL OR myColumn = ''
    

    To get only null values:

    SELECT * FROM myTable WHERE myColumn IS NULL
    

    To get values other than null and empty:

    SELECT * FROM myTable WHERE myColumn <> ''
    


    And remember use LIKE phrases only when necessary because they will degrade performance compared to other types of searches.

    0 讨论(0)
提交回复
热议问题