user1556433
user1556433

Reputation:

How do I write numerals in a string literal?

My following Delphi code is throwing a compiler error: incompatible type: string and integer in line

SQL.Text := 'Select ColumnA from TableA where ColumnA NOT IN ('+ 3 + ',' + 4 +')';

How do I put the numbers in the SQL statement?

Upvotes: 2

Views: 298

Answers (2)

whosrdaddy
whosrdaddy

Reputation: 11860

When writing these sort of statements (and parameters are not in scope), try to use the Format function:

SQL.Text := Format('Select ColumnA from TableA where ColumnA NOT IN (%d,%d)',
                  [Firstval, SecondVal]);

One big advantage writing the query this way is that you keep the SQL statement readable (like when you use parameters).

Upvotes: 7

iMan Biglari
iMan Biglari

Reputation: 4776

This line should look like this:

SQL.Text := 'Select ColumnA from TableA where ColumnA NOT IN (3,4)';

Upvotes: 1

Related Questions