December 10, 2014 at 5:28 pm
Dear all:
I created an application that will upload a csv file and insert it to a SQL table. Some of the columns allow nulls and I would like the null values to show in the SQL table. However the null values didn't show properly in the table.
For example:
id name age salary
1,Mike,null,$100000
2, John,34,$67000
for the first row the age column it'll insert "null" as string
I then tried the following
id name age
3, Luke,,$89000
The inserted value for age is an empty string
I then tried the following
3, Luke,"",$75000
The inserted value for age is double quate
I then tried the following
3, Luke,"Null", $210000
The inserted value is "Null".
So what should I do to make sure a null value can be inserted to the table?
Thank you for the help!
December 10, 2014 at 6:14 pm
MaggieW (12/10/2014)
Dear all:I created an application that will upload a csv file and insert it to a SQL table. Some of the columns allow nulls and I would like the null values to show in the SQL table. However the null values didn't show properly in the table.
For example:
id name age salary
1,Mike,null,$100000
2, John,34,$67000
for the first row the age column it'll insert "null" as string
I then tried the following
id name age
3, Luke,,$89000
The inserted value for age is an empty string
I then tried the following
3, Luke,"",$75000
The inserted value for age is double quate
I then tried the following
3, Luke,"Null", $210000
The inserted value is "Null".
So what should I do to make sure a null value can be inserted to the table?
Thank you for the help!
Don't insert into the final table directly. Always load a staging table first so that you can clean up anomalies like this one and validate data. After you load the staging table, do a simple UPDATE to change the world "NULL" to a real NULL.
--Jeff Moden
Change is inevitable... Change for the better is not.
December 11, 2014 at 1:17 am
MaggieW (12/10/2014)
Dear all:I created an application that will upload a csv file and insert it to a SQL table.
Can you share apllication code? Is it T-Sql, c#, ... ?
December 11, 2014 at 9:48 am
Here's a link you can refer to:
http://www.mssqltips.com/sqlservertip/2556/net-application-for-sql-server-data-management/
December 11, 2014 at 11:04 am
Thank you all for your help.
I decided to use a case when statement in my TSql as follows
insert into Employee (ID, Name, Age, Salary) values (@ID, @Name, (case when @Age = 'NULL' then (Select Null) else @Age end), @Salary)
Thank you again!
December 11, 2014 at 11:28 am
December 11, 2014 at 11:46 am
Thank you! Jeebee
I learned something new. It's indeed a smart way!
Thank you so much again!
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply