Solved

SQL Server 2008, Numeric Data Type & NULL Values

Posted on 2011-09-06
8
345 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
can we get a small sample (first few lines including one without special price) of your CSV file?
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 8

Expert Comment

by:stalhw
Comment Utility
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
Comment Utility
Here is a sample of the csv file.
export-all-products.csv
0
 
LVL 8

Accepted Solution

by:
stalhw earned 500 total points
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 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

11 Experts available now in Live!

Get 1:1 Help Now