tags:

views:

64

answers:

3

Good Morning,

Say I have an insert statement:

Insert INTO tblTest (fieldOne,FieldTwo,fieldThree) VALUES ('valueOne','valueTwo','null')

This statement doesn't seem to want to insert a null value into the database... I have also tried to insert the word "nothing".

Has anyone any ideas how to make this work? I am using SQL server 2005.

+1  A: 

Try

Insert INTO tblTest (fieldOne,FieldTwo,fieldThree) VALUES ('valueOne','valueTwo',NULL)

Check for fieldThree not to be NOT NULL.

If you're trying to INSERT 'NULL' string, then just check if fieldThree is varchar type.

hgulyan
+2  A: 

First of all, instead of 'null', try null (lose the quotes)

Then check that the fieldThree column on TblTest doesn't have any constraint prohibiting the use of null values...

Martin Milan
+1, when you put quotes around the NULL you create a literal char(4) string of the word 'NULL' and not the undefined value NULL.
KM
A: 

Insert INTO tblTest (fieldOne,FieldTwo) VALUES ('valueOne','valueTwo')

Navaneethan
Thanks for the help - you and Martin - much appreciated.
J Harley
Be careful with this one J Harley - it's possible you could have a default value being applied by the database if it has a default constraint. If you really want null (and have a default constraint), this won't work.
Martin Milan
However, if you don't explicitly need a null in there - you're just not able to specifiy a value at the time - then this is fine.
Martin Milan