Solved

SQL Server 2008, Numeric Data Type & NULL Values

Posted on 2011-09-06
8
348 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
  • 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
 
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
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.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
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 …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now