Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i have one table in my database and table contains some null and some not null(eg. 11,12) values, i want only all not null values from table and from all columns of table..how it is possible please let me if any one have answers....????????????
Posted
Comments
Maciej Los 24-Jul-13 9:00am    
Please, be more specific and provide some example data and expected output.

Try this
SQL
SELECT *FROM table_name WHERE column_name IS NOT NULL
 
Share this answer
 
Comments
mohansahu 24-Jul-13 9:16am    
if i have more dan 100 columns in my table then???
[no name] 24-Jul-13 9:20am    
It won't be affected..it will give the result..
then also if you have doubt, try and show the error..
mohansahu 24-Jul-13 9:48am    
still not working..
[no name] 24-Jul-13 9:50am    
what is the error you are getting..??
mohansahu 24-Jul-13 9:55am    
An expression of non-boolean type specified in a context where a condition is expected
Hi Mohan,


Try using below command

SQL
SELECT fields FROM table_name WHERE column_name IS NOT NULL


For reference try this link[^]

Hope this helps you a bit.

Thanks,
RK
 
Share this answer
 
v3
Comments
[no name] 24-Jul-13 9:02am    
He wants not null values.
mohansahu 24-Jul-13 9:16am    
if i have more dan 100 columns in my table then???
Please, read my comment to the question.

Not enough information, but it might work for you:
SQL
SELECT Col1, Col2, Col3
FROM TableName
WHERE COALESCE(Col1, Col2, Col3) IS NOT NULL
 
Share this answer
 
Comments
mohansahu 24-Jul-13 9:16am    
if i have more dan 100 columns in my table then???
Maciej Los 24-Jul-13 9:26am    
What you expect from me?

By The Way: It sounds like bad table design...
mohansahu 24-Jul-13 9:53am    
its not bad table design its called sql server support engg problem what is i am facing now..
[no name] 24-Jul-13 11:20am    
No, to be accurate it's called supporting a bad design.

What if you have 100 columns? The answer is the same whether you have 10, 100 or a 1000 columns.
Maciej Los 24-Jul-13 11:22am    
Exactly!
Thank you for support ;)
Hi,

Check the below code.... I think it will helps you.

SQL
DECLARE @SqlString VARCHAR(1000), @TableName VARCHAR(100)

SELECT @TableName='Table_Name'

-- If you need to compare only last 200 columns (20 to 220) then add WHERE condition 
SELECT @SqlString=COALESCE(@SqlString+',','')+Name FROM syscolumns WHERE  OBJECT_NAME(ID)=@TableName AND colorder BETWEEN 20 AND 220

SELECT @SqlString='SELECT COALESCE('+@SqlString+') FROM '+@TableName

PRINT @SqlString
EXEC(@SqlString)

Regards,
GVPrabu
 
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