Solved

search SQL table for null in each column

Posted on 2014-03-31
6
598 Views
Last Modified: 2014-03-31
Hi Experts,

is there an easy(ish) way to run a select statment to run across each colum to see if there are null values?

thanks

Simon
0
Comment
Question by:SimonPrice33
[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
  • 2
  • 2
  • 2
6 Comments
 
LVL 9

Accepted Solution

by:
edtechdba earned 500 total points
ID: 39966324
It sounds like checking to see which columns can be nullable first may help, here's an example below.
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMS
WHERE TABLE_SCHEMA = 'dbo'
  AND TABLE_NAME = 'YourTable'
  AND IS_NULLABLE = 'YES'

Open in new window


Then take your column names from the query above and add them to the WHERE clause below.

SELECT *
FROM YourTable
WHERE (col1 IS NULL
  OR col2 IS NULL
  OR col3 IS NULL)
  -- and so on until you've included all columns that are nullable

Open in new window

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39966337
do you mean NULL in all columns for a single row?
I agree there is nothing "simple", the only way is the one above, as you have to consider that for columns that cannot be null there will be some "default" value (at least).
you might want to consider such "default values" to be like a NULL value for your consideration...
0
 

Author Closing Comment

by:SimonPrice33
ID: 39966374
Im not checking to see if they are nullable, i was hoping that i wouldnt have to specify each column but thought that would be the only way.

thanks

simon
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 9

Expert Comment

by:edtechdba
ID: 39966401
If there are columns that are not nullable in your table, then you'll reduce the # of columns when searching for NULL values if you run first query before checking for NULL values.

Just a thought. Thank you.
0
 

Author Comment

by:SimonPrice33
ID: 39966411
the genuis who put this together made all fields nullable...
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39966526
sorry, you will have to bite the nail here...
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

635 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