01-30-2007, 03:13 PM
I have a SQL Insert statement that sends data to a SQL Server table.
The values are picked up from a form using ASP.
Sometimes the values will be blank or do not require and answer.
How can I insert these values as NULL into SQL server?
I am getting an error like the following:
Microsoft OLE DB Provider for SQL Server error '80040e14'
Line 1: Incorrect syntax near ','.
end.asp, line 46
01-30-2007, 03:20 PM
can you response.write out the sql query.
I've never had any issues inserting null value as long as your field that your inserting it to will allow this.
01-30-2007, 03:34 PM
Here is the statment:
Insert Into [Score Data] (fName, lName, Ngh, Level, NumSelling, DelTimeSlot, DelStation, Ck1, Ck2, Ck3, Ck4, Ck5, Ck6, Ck7, Ck8, TotCases, wT1, wT2, wT3, startTime, endTime) Values ('Joe', 'Smith',12,2,12,2,61,1,2,3,4,5,6,7,8,36,1,2,3,'8:00','9:00')
The problem is, the fields listed below are not required and sometimes will be blank.
So when the insert statement excutes and there is no value in one of these fields - it gives any error. How can I set them to null?
Also, Allow Nulls is checked in SQL Server.
01-30-2007, 03:44 PM
ok, the sql looks fine.
maybe just do a check on all values before you insert them, you can could this several ways.
If strValue = "" Or IsNull(strValue) Then strValue = " "
If Len(strValue) = 0 Then strValue = " "
or is the field is an Int, then
If numValue = "" Or IsNull(strValue) Then strValue = 0
though this still doesn't seem write, you should be able to insert null values no prob. maybe try wrapping all your Int values in single quotes aswell,
if that doesn't work, post the sql insert back again with the values null, so we can see exactly what it looks like with null values.
hope this helps.
01-31-2007, 12:06 PM
Response.Write your query.
The error is saying that you have a syntax error, not a Null error.
It would seem that you have an extra comma at the end of your query when the fields are not required.
01-31-2007, 03:03 PM
just look to see if there is a value in the variable after you assign a value to it, if it has no value, assign it a value of 0. Then when you run your sql statement you will not have a ,, in the sql statement
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.