?
Solved

search SQL table for null in each column

Posted on 2014-03-31
6
Medium Priority
?
608 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 1000 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

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…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

719 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