Click here to Skip to main content
15,905,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am trying to retrieve all values using the column name in the Where condition: I have my reasons using this method (this question is to help answer my errors not my actual codes) :

SQL
SELECT *
FROM Table1
WHERE Column1 IN (Column1)


The problem is it does not take in NULL values in column 1 during return. How do I take in NULL values as well?
Posted
Comments
[no name] 7-Oct-15 6:00am    
Maybe you mean?
SELECT *
FROM Table1
WHERE Column1 IN ('a', 'b', 'c') OR Column1 IS NULL

That query makes no sense, however if you want to check for nulls

SQL
select fieldlist from table where somefield is null


or to ignore nulls

SQL
select fieldlist from table where somefield is not null
 
Share this answer
 
This is the sample for your requirement; refer this and implement the same in your requirement.

SQL
declare @tab table
(
	Id int,
	name varchar(100)
)

insert into @tab
values (1,'n'),(2,'d'),(3,null),(4,'g'),(5,null)

select * from @tab
where name in ('n','d') or name is null
 
Share this answer
 
SELECT *
FROM TableA
WHERE Col1 IN ('a','b','c')

UNION ALL

SELECT *
FROM TableA
WHERE Col1 IS NULL
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900