I'm trying to set up a parameterized SQL query using a TQuery, and I'm running into a couple of problems. I can do a boring static query, but as soon as I try adding parameterization stuff, it all falls over. If I walk into the Prepare or Open, I find that my parameters are replaced with '?'; in other words, the Query hasn't successfully matched them up with the Params.
I also want to replace the TableName with a parameter, but I'm not sure if this is legit.
My other problem is that I want a WHERE clause that matches a date/time: WHERE TheDateTime = :myDateTime; something like that; but I'm not sure of the SQL syntax. I managed to get as far as WHERE TheDateTime < CAST('1/1/2002' AS DATE); but this doesn't work for equals, only for greater than or less than; and I can't get it to work for a time, only a date.
-- Doug Burbidge mailto:doug@ultrazone.com
Code:
Query1.SQL.Clear;
Query1.SQL.Add('SELECT * FROM ' + TableName + ' WHERE ID = :Game;');
Query1.ParamByName('Game').AsString := '"0001"';
Query1.Prepare;
Query1.Open;
My other problem is that I want a WHERE clause that matches a date/time: WHERE TheDateTime = :myDateTime; something like that; but I'm not sure of the SQL syntax. I managed to get as far as WHERE TheDateTime < CAST('1/1/2002' AS DATE); but this doesn't work for equals, only for greater than or less than; and I can't get it to work for a time, only a date.
-- Doug Burbidge mailto:doug@ultrazone.com