这样的sql语句该怎么样写?(100分)

L

Linnow

Unregistered / Unconfirmed
GUEST, unregistred user!
a是一个整型变量
那这句select语句在delphi中应该怎样写呢?
select * from tablename where id=a
前提是不能用参数查询(即select * from tablename where id=:b,再将a的值赋给参数b)
直接用sql写应怎么写啊?
也就是那个a应该怎么个写法?
 
Query.SQL.Add('select * from tablename where id=' + IntToStr(a));
 
这样我也知道啊!
不用这种方法呢?
是否还有其他方法啊!
最好是直接用a的!
 
难道就没人知道啊!
高手呢?
 
不可能直接把a写在SQL语句中的!SQL语句是它不是在DELPHI环境中执行
它只不过是通过控件传递给数据库来执行的,所以你的想法是不可能实现的!
 
PB好像可以
 
Query.SQL.Add(format('select * from tablename where id=%d',[a]));
 
这下你该满意了吧,
Query.SQL.Add(Format('select * from tablename where id=%d',[a]));
 
根据你的描述,a既然是一个整形变量,那么可以这样写
Query.sql.text := 'select * from tablename where id='''+IntToStr(a)+'''';
你到底想怎么写呢?
 
如果字段ID如果是数字则:'select * from tablename where id='+IntToStr(a),如果是
字符串则:'select * from tablename where id='''+IntToStr(a)+''''
如果还不行,基本上你是无理要求
 
谢谢各位啦!
高手看来挺多的嘛!
以后请大家多多照顾喽!
 
顶部