Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to handle N/A or Unknown Data

Posted on 2011-02-24
6
Medium Priority
?
339 Views
Last Modified: 2012-05-11
Hi,

I have a field that takes numbers, a double type 100.45. However, the user says that sometimes the value is unknown. So, there are like two states for this field:

1. A number 0 to 1,000
2. Unknown or N/A value. Somebody has not measured it yet, so there is no value yet.

How can I design my table or the column to handle values like this and cover both states? I like to have a column with numbers only, and no chars in it to keep data integrity.

Any suggestions on how to handle this?

Thanks


0
Comment
Question by:gtrapp
6 Comments
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 1000 total points
ID: 34976047
Just allow nulls in the column definition.
0
 
LVL 41

Assisted Solution

by:Sharath
Sharath earned 500 total points
ID: 34976052
If possible, define your column as decimal(6,2) and insert N/A, Unknown values as NULL. If that is not possible and you have to have N/A and Unknown,
you have to define your column as varchar to hold string data.
0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 34976054

The best way is to use nulls for unassigned values
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 29

Assisted Solution

by:Paul Jackson
Paul Jackson earned 1000 total points
ID: 34976071
If you allow nulls when you do a select you can handle the null using the ISNULL function like this :

Select ISNULL(mycolumn, 'N/A')
FROM mytable

This will return the column value if not null and return what is specified in the quotes if it is null.
0
 
LVL 57

Assisted Solution

by:Raja Jegan R
Raja Jegan R earned 500 total points
ID: 34978462
>> 1. A number 0 to 1,000
2. Unknown or N/A value.

Since you have stored character values in a numeric column, the best way without altering the table would be to use ISNUMERIC function as given below:

SELECT * FROM ur_table
WHERE ISNUMERIC(ur_column_name) = 1

If you are ok to change table structure along with data, then change your column datatype to INT and change those invalid characters as 0 or null..
0
 

Author Closing Comment

by:gtrapp
ID: 34980846
Thanks for the advice,
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

810 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