Page 1 of 1

inserting NULL values in queries

Posted: Fri 15 Oct 2010 11:30
by JensFudge
Hi
How do I insert a NULL value in a query?

Q.SQL.Add('SELECT * FROM TABLE1');

Q.SQLINSERT.add('INSERT INTO TABLE1');
Q.SQLINSERT.add('(FIELD1, FIELD2)');
Q.SQLINSERT.add('VALUES');
Q.SQLINSERT.add('(:field1, field2)');

Q.open;

Q.insert;
Q.fieldByName('Field1').asInteger := NULL;
Q.fieldByName('Field2').asInteger := 4;
Q.Post;

That obviously wont work...
I have tried with .Clear, but got some exception..

Best regards
Jens Fudge

Posted: Fri 15 Oct 2010 13:34
by AndreyZ
Hello,

You have an error in SQLInsert, the second parameter is written without colon.

Posted: Fri 15 Oct 2010 13:34
by AndreyZ
You can use the following code:

Code: Select all

Q.FieldByName('Field1').Value := NULL;

Posted: Fri 15 Oct 2010 13:40
by JensFudge
AndreyZ wrote:Hello,

You have an error in SQLInsert, the second parameter is written without colon.
In case you hadn't noticed.. This is just example code off the top of my head..
I dont really have a table named Table1 with Field1 and Field2...
:wink:

Posted: Fri 15 Oct 2010 13:41
by JensFudge
AndreyZ wrote:You can use the following code:

Code: Select all

Q.FieldByName('Field1').Value := NULL;
oh.. ok.. thanks