Solved

SQL Server 2008, Numeric Data Type & NULL Values

Posted on 2011-09-06
8
359 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
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: 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Re-appearing SQL Server Agent jobs 7 46
converting integer data type to time data type in sql 4 60
Help with SQL pivot 11 49
HIghlights of SSIS? 3 44
Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

739 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