We have a form that has multiple fields of different data type, including string, datetime and numbers.
Our customer want to be able to write N/A (Not Applicable) in any of these fields, as well as being able to leave it blank.
Does someone has an idea on how I should design my Sql Server table so it can support a value, NULL or N/A?
We are using Sql Server 2008.
Have you ever thought about how SQL Server stores data in its data files? As you know, data in tables is stored in row and column format at the logical level, but physically it stores data in data pages which are allocated from the data files of the database.
The disk space allocated to a data file is logically divided into pages which is the fundamental unit of data storage in SQL Server. A database page is an 8 KB chunk of data. When you insert any data into a SQL Server database, it saves the data to a series of 8 KB pages inside the data file.
So, you could use 0 for no, 1 for yes, and NULL could be allowed to represent N/A. Thanks Tim for replying. I am new to SQl server.
Classic tables. The simplest way to store JSON documents in SQL Server or SQL Database is to create a two-column table that contains the ID of the document and the content of the document.
If N/A and blank are truly different values you need to support, I would say to create the field as a nullable field (in which case the NULL would represent the blank value), and then include a second bit field for [FieldName]NotAvailable or [FieldName]Specified.
Granted, you would be using two separate fields to represent a single logical concept, trying to force it all into one field causes two concepts to be stored in the same field (the field is interpreted one way, unless there is some magical value, then it means something else). This way, with the separate field, it is far more clear what the expected behavior of the fields is.
If they only want one state, you can, as other folks indicate simply translate the null:
SELECT COALESCE(thecolumn1,'N/A') AS mycolumnalias
IF it is discovered that they really desire to have the 'tri-state' on the column, you can create a companion VARCHAR column.
SELECT COALESCE(thecolumn1, companioncolumn1,'N/A') AS mycolumnalias
Advantages:
Disadvantages:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With