Solved

remove null column in SQL

Posted on 2011-02-11
11
442 Views
Last Modified: 2012-06-21
Is it possible removed any columns that is null?
sample select *from table1
0
Comment
Question by:VBdotnet2005
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
  • +1
11 Comments
 
LVL 3

Expert Comment

by:sunezapa
ID: 34876425
remove rows by Select * from table1 where column is not null
and
show nulls as something else by Select ISNULL(column,'') from...

but what do you exactly means with "Remove Columns"?
0
 

Author Comment

by:VBdotnet2005
ID: 34876583
let's say it a result has any column that is null, I want to be able to remove it from the result
0
 

Author Comment

by:VBdotnet2005
ID: 34876589
select field1, field2, field3 from tabl1

result

john      doe      null
jim      doe      null
james      doe      null
            

I dont want to get null column

Just this

john      doe       
jim      doe       
james      doe       

0
Technology Partners: 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!

 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 34876592
SELECT *
FROM YourTableNameGoesHere
WHERE YourColumnNameGoesHere IS NOT NULL
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 34876595
Ah, that is different.  You will have to handle that in your front-end.
0
 
LVL 3

Expert Comment

by:sunezapa
ID: 34876618
try the ISNULL thing...
Select  field1, field2, ISNULL(field3,'') from table1

Open in new window

it will not return any NULL values (in example an empty string is returned instead)...
0
 
LVL 41

Expert Comment

by:Sharath
ID: 34876986
If your result is

john      doe      null
jim      doe      null
james      doe      abc

What would be your expected result?
           
0
 

Author Comment

by:VBdotnet2005
ID: 34879362
Above three columns
If the entire column are null,I want to remove it
If partials, leave it alone
0
 
LVL 3

Expert Comment

by:sunezapa
ID: 34879566
no SQL code can know what "the next records" will be, so it is not possible to decide to bring a column or not at runtime.
Do the "filtering" in your frontend.
Maybe ask more detailed what the purpose is - there may be easy solutions, other than what you describe...
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 125 total points
ID: 34879599
If you are unable to solve this in the front-end (though why you would even consider doing this is beyond me) and are adamant to do it with T-SQL alone then consider something like this:
IF EXISTS (
	SELECT 1
	FROM dbo.YourTable
	WHERE YourColumn IS NOT NULL)
	SELECT Col1, Col2, YourColumn 
	FROM dbo.YourTable
ELSE
	SELECT Col1, Col2 
	FROM dbo.YourTable

Open in new window

0
 
LVL 41

Expert Comment

by:Sharath
ID: 34880384
What is your SQL Server version?
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how the fundamental information of how to create a table.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question