Share via

what different between blank and null ?

ahmed salah 3,216 Reputation points
2020-11-04T00:27:11.13+00:00

I work on SQL server 2012 i face issue I have table have column family Name

this column may be Null or blank

so I need to get data from Table Employee when Column Family Name is not null

or not blank so How to do that please ?

select * from Employee where Family Name is not null or ??????????
How to represent is not blank

Developer technologies | Transact-SQL
Developer technologies | Transact-SQL

A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.

SQL Server | Other
SQL Server | Other

Additional SQL Server features and topics not covered by specific categories


3 answers

Sort by: Most helpful
  1. Viorel 126.9K Reputation points
    2020-11-04T08:19:28.917+00:00

    Consider this solution too:

    select * 
    from Employee 
    where [Family Name] <> ''
    

    It will exclude null and blank values.

    Was this answer helpful?

    0 comments No comments

  2. Uri Dimant 211 Reputation points
    2020-11-04T07:54:16.67+00:00

    Simple , BLANK is a known value but NULL us unknown value

    Was this answer helpful?

    0 comments No comments

  3. MelissaMa-msft 24,246 Reputation points Moderator
    2020-11-04T00:52:36.793+00:00

    Hi @ahmed salah ,

    I will provide one example from below and you could check whether it is helpful to you.

    I would like to use ISNULL to include the blank and null conditions.

    declare @Employee  table  
    (id int,  
    FamilyName varchar(20))  
      
    insert into @Employee values  
    (1,''),  
    (2,null),  
    (3,'Mary')  
      
    select * from @Employee where FamilyName is null  
    --id FamilyName  
    --2 NULL  
      
    select * from @Employee where FamilyName=''  
    --id FamilyName  
    --1  
      
    select * from @Employee where FamilyName='' or FamilyName is null  
    --id FamilyName  
    --1  
    --2 NULL  
      
    select * from @Employee where isnull(FamilyName,'')=''  
    --id FamilyName  
    --1  
    --2 NULL  
    

    In your situation, you could have a try with below queries:

    --option 1  
       select * from @Employee where isnull(FamilyName,'')<>''  
    --option 2  
        select * from @Employee where FamilyName<>'' and FamilyName is not null  
    

    If there is no index on FamilyName column, you could choose any of them.

    If you have index on FamilyName column, you could try with option 2 because of performance benefits since isnull is one function and causes that predicate to be non-SARGable.

    Best regards
    Melissa


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    Hot issues October--Users always get connection timeout problem when using multi subnet AG via listener. Especially after failover to another subnet

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.