现在的位置: 首页 > 综合 > 正文

delphi sql语句字符串的问题

2013年05月09日 ⁄ 综合 ⁄ 共 1423字 ⁄ 字号 评论关闭
delphi sql语句字符串的问题 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiDB/html/delphi_20061215232313281.html
SELECT   *  
  FROM   saveque  
  WHERE   rdate<#2006-12-7#;  
  (ACCESS库)  
  以上sql语句我放在ADOQuery1.SQL.Add('select   cpn   from   saveque   where   rdate<'+'#''+datetostr(DateTimePicker1.Date)+'#'+'');中老不对  
   
  应该怎么写啊!我是菜鸟帮帮我!  
  另外!这句sql查询语句在SQL2000server中也是这样写吗?  
  还有一个问题如果我想指定范围查询应该怎么写呢?  
  比如   2004-1-1     到   2005-1-1   日之间的所有数据?谢谢了  
   
 

ADOQuery1.SQL.Add('select   cpn   from   saveque   where   rdate<??')  
  adquser.Parameters.ParamByName('??').Value:=datetostr(DateTimePicker1.Date)  
 

select   cpn   from   saveque   where   rdate<'''+'#'+datetostr(DateTimePicker1.Date)+'#'+''  
  注意rdate<'''这里再加两个引号

这样写是对的,我验证过了:  
  select   cpn   from   saveque   where   rdate<#'+datetostr(DateTimePicker1.Date)+'#'  
   
  mssql   中这样写select   cpn   from   saveque   where   rdate<'+datetostr(DateTimePicker1.Date);  
   
  指定查找范围(mssql):select   cpn   from   saveque   where   rdate   between   '''   +   datettostr(datetimepicker1.date)   +   '''   and   '''   +   datettostr(datetimepicker2.date)   +   ''''  
   
 

mssql   中这样写select   cpn   from   saveque   where   rdate<'+datetostr(DateTimePicker1.Date);  
   
  ---------------------------------------  
   
  不好意思,应该是:  
   
  sqlstr:='select   cpn   from   saveque   where   rdate<'''+datetostr(DateTimePicker1.Date)   +   '''';

最好的方法是这样的:  
   
  'select   cpn   from   saveque   where   rdate<:aa   '  
   
  然后再在adoquery1.open前面放上下面这一句就可以啦.  
  adoquery1.Parameters.ParamByName('aa').Value:=trim(DateTimePicker1.Date);  
   
  在access   和sqlsever中通杀!

最后一个最简单明了!结帖!参与有分!谢谢!

结帖

【上篇】
【下篇】

抱歉!评论已关闭.