Solved

SQL Server 2008, Numeric Data Type & NULL Values

Posted on 2011-09-06
8
365 Views
Last Modified: 2012-05-12
Please forgive me as I am completly new to SQL Server.  I am importing a CSV file from an e-commerce site into a SQL Server 2008 table using a dtsx package I created in BIDS.  I established some of the columns within the table, such as "price" and "special price," as Numeric (18, 2) data types.  However, within the spreadsheet that I am importing "special price" only has a value if the item is on sale; otherwise, it is empty.  Unfortunitly, when it is imported into SQL all of the NULL values for "special price" are being populated with a zero.

This is causing me some problems because I am manipulating the data within the table, exporting a csv file and then uploading the information back into the e-commerce store.  The e-commerce store interprets the zero vaule within the "special price" field as the item being on sale for a price of $0.00.  How can I get SQL to retain the value of NULL during the import process for my fields with a Numeric data type?  

0
Comment
Question by:csimmons1324
[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
  • 4
  • 2
  • 2
8 Comments
 
LVL 8

Expert Comment

by:stalhw
ID: 36490969
first, does your table allows null value in the price field?
is there a default value of 0 for that field? that would explain the problem...

worst case you could always do a search and replace on your CSV file prior to importing it to convert blanks to Null
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 36491006
Check if (1) the column on the SQL side is set to NOT NULL with a default of 0; (2) the values are coming over from Excel as NULL. One way to ensure this is using NULLIF. If the SQL side allows NULLs, then you can make the field NULLIF(CONVERT(NUMERIC(18, 2), {some value}), 0) or using similar syntax retrieve the data as NULL like so SELECT NULLIF([special price], 0) FROM your_table.
0
 

Author Comment

by:csimmons1324
ID: 36491096
When I go into the design view for the table, the field "special price" is setup as numeric(18,2) and to Allow Nulls.  If I go into the properites of the field, the Default Value or Binding is empty.

The only thing that I see that contains a zero in the properties of the column is the Identity Seed and Identity Increment properties.  
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 8

Expert Comment

by:stalhw
ID: 36491126
can we get a small sample (first few lines including one without special price) of your CSV file?
0
 
LVL 8

Expert Comment

by:stalhw
ID: 36491138
the other simple solution (if there's never a real special price of 0$)
is to add an UPDATE statement at the end of your DTS package...

UPDATE mytable
SET specialPrice=null
WHERE specialPrice=0

(or create a trigger on INSERT to do the same)
0
 

Author Comment

by:csimmons1324
ID: 36491196
Here is a sample of the csv file.
export-all-products.csv
0
 
LVL 8

Accepted Solution

by:
stalhw earned 500 total points
ID: 36497001
Ok, I tested importing the CSV, and it correctly sets Null for all missing special prices...

You need to look inside your DTS package, find the 'transform' [...] button, and look at the translation, is the allowNull checkbox checked for that column?
The problem has to be in the import package that was made...
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 36497161
Agreed. I could not find anything outside of column that had 0's in it which could be accidentally assigned to the special price field for import...but again that points to an issue with package. Good luck. I will leave you with stalhw as he appears to have things in hand.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

624 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