How to insert null as a value for the sql table DateTime column from excel?
Hi All,
i am able to insert the values from excel sheet columns data to the corresponding columns of an sql table.
But the problem is
in my execl sheet i have some date columns.In those some rows are having data(date) and some rows are empty.
Now when i am sending these data to a datetime column of sql table,the rows which are having dates are showing as it is.But the rows which are empty are showing with a default date(1900-01-01 00:00:00.000) in the sql table.
But i need Null instead of 1900-01-01 00:00:00.000.
If i check by inserting the null values from sql.I am getting null values to the date columns.
Re: How to insert null as a value for the sql table DateTime column from excel?
You aren't specifying your columns in your INSERT query, just have 2 sql statements, one INSERT as you have and another with columns specified leaving out the column that could be null. SQLS will then put a null in by default
Re: How to insert null as a value for the sql table DateTime column from excel?
Of course you haven't you are missing the point. If you do not want to include a field in an insert remove if from the sql, so if you didn't want month and year:
Re: How to insert null as a value for the sql table DateTime column from excel?
Kyle,
How can i do statically like that by removing Date fields and their corresponding values from the query.
Because i need to insert the value if there is a value(date) if not only it will insert the null value in the database.
If i remove the fields how can i insert the data if there is data.
and you are asking me why i am inserting these values as strings.
because,I found the syntax in some where(exactly i don't know the syntax here to insert.)
Please correct me if i am not understanding your point.
Re: How to insert null as a value for the sql table DateTime column from excel?
Kyle,
Ya i have setup my database correctly.I am using Datetime for date columns and all others are nvarchar as datatypes.
and i have also checked by programatically giving the value as Null by checking the cell value if empty.But no use.
But if we remove statically the columns and their values.I am getting Null in the database.But this is not the required case.
Re: How to insert null as a value for the sql table DateTime column from excel?
Kyle,
Right now i have 4 date columns.If i need to generate the query dynamically then i need to write 16 probabilities.I am doing that and it is working too.
But it is a lengthy process.
Is there any optimization for this?
If any solution at you please share with me.
Re: How to insert null as a value for the sql table DateTime column from excel?
Kyle,
Can you please change my query how to pass the value.
ColE,ColF,ColG,ColP are the variables in which i am storing the date column each row value.Similarly others.
I have tried but i am getting syntax errors when debugging.
Re: How to insert null as a value for the sql table DateTime column from excel?
It's quite simple, I think you think it's more complicated than it is.
If there is no value in the cell, don't pass the quotation marks in your sql string for that field, just pass "Null", not "'Null'"
Instead of putting them in the sql statement itself, add any quotation marks to the variables if required, then all you need to include are commas between the variables.
---------- Post added at 02:05 PM ---------- Previous post was at 01:59 PM ----------
Bookmarks