• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 203
  • Last Modified:

Can I use like '%' to search Null value?

Dear all experts,

  I've the following quesiton about T-SQL statement, please kindly some help.

  The table structure is as follow:

  ID    Name
  ------------
  1      Tom
  2      John
  3      Peter
  4      NULL
  5      NULL
  6      NULL

 When I type "Select * from table where name like '%'", it returns the following:


  ID    Name
  ------------
  1      Tom
  2      John
  3      Peter

  What I would like to do is getting the data even the value is set to Null, does anyone tell me how to do so?  Or, I need to convert all NULL value to something first?

  Thanks in advance.

0
LegalIT
Asked:
LegalIT
1 Solution
 
ispalenyCommented:
Select * from table where isnull(name,'') like '%'

Select * from table where name like '%' or name is null
0
 
JulianvaCommented:
select * from tablename where columnname is not null
0
 
JulianvaCommented:
select * from tablename where name is not null
0
 
lluthienCommented:
just a comment,
but this one from Ispaleny:

Select * from table where isnull(name,'') like '%'

i find esthetic :)
0
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
If you want all data, why do you need a where clause?
Just a simple "SELECT * FROM table" should be the answer for your question.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now