Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread Sql with diferrent value type
Tue, Mar 16 2010 6:55 AMPermanent Link

Hershcu Sorin

Hello

I have the following code:

query1.SQL.Text := 'SELECT Field0, Field1, Field2 FROM Table1';
query1.Open;

query2.SQL.Text := 'INSERT INTO Table2 (Field0, Field1, Field2, Field3)' +
          'VALUES ('  +  myLocalVar + ', '  +
query1.FieldByName('Field1').AsVariant + ', '  +
query1.FieldByName('Field2').AsVariant +  ')';
query2.ExecSql;

The problem is that Field1, Field2 can be integer and can be NULL.
What are the correct statements to create that code lines?

Thanks
Sorin




Tue, Mar 16 2010 7:33 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Sorin

Try this

SQL.Text := 'INSERT INTO Table2 ((Field0, Field1, Field2, Field3) SELECT'  + myLocalVar + ' Field0, Field1, Field2 FROM Table1'

Roy Lambert [Team Elevate]
Tue, Mar 16 2010 1:58 PMPermanent Link

Hershcu Sorin

> Try this
> SQL.Text := 'INSERT INTO Table2 ((Field0, Field1, Field2, Field3) SELECT'
> + myLocalVar + ' Field0, Field1, Field2 FROM Table1'

Simple and work.

Thanks Sorin

Image