Solved

search SQL table for null in each column

Posted on 2014-03-31
6
594 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

751 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