Solved

SQL Server 2008, Numeric Data Type & NULL Values

Posted on 2011-09-06
8
356 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 59

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 59

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

756 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