总结一下SQL语句中引号()、quotedstr()、()、format()在SQL语句中的用法
2011-08-08 14:53
399 查看
View Code
编辑器加载中...
总结一下SQL语句中引号('')、quotedstr()、('''')、format()在SQL语句中的用法以 及SQL语句中日期格式的表示(#)、('''') 在Delphi中进行字符变量连接相加时单引号用(''''''),又引号用('''''''')表示 首先定义变量 var AnInt:integer=123;//为了方便在此都给它们赋初值。虽然可能在引赋初值在某些情况下不对 AnIntStr:string=''456''; AStr:string=''abc''; AFieldName: string=''字符型编号''; ATableName: string=''YourTable''; ADate:Tdatetime=now; Adoquery1:tadoquery; 1,Delphi语句 adoquery1.sql.text:= ''select 字符型编号 from YourTable where 字符型编号=''abc'' and 整型编号=123''; 等价于 adoquery1.sql.text:= ''select ''+AFieldName+'' from ''+ATableName+'' where ''+AFieldName +''=''''''+AStr+'''''' and 整型编号=''+AnIntStr; 也等价于 adoquery1.sql.text:= ''select ''+AFieldName+'' from ''+ATableName+'' where ''+AFieldName +''=''+QuotedStr(AStr)+'' and 整型编号=''+Inttostr(AnInt); 传到数据库服务器为: select 字符型编号 from YourTable where 字符型编号=''abc'' and 整型编号=123 2,Delphi语句中日期表示 对于access数据库: adoquery1.sql.text:= ''select 字符型编号 from YourTable where 日期型字段=#2003-12-01#''; 等价于: adoquery1.sql.text:= ''select 字符型编号 from YourTable where 日期型字段=#''+FormatDateTime(''yyyy-MM-dd'',now)+''#''; 传到服务器为: select 字符型编号 from YourTable where 日期型字段=#2003-12-01# 对于MSSQL数据库: adoquery1.sql.text:= ''select 字符型编号 from YourTable where 日期型字段=''2003-12-01''''; 等价于: adoquery1.sql.text:= ''select 字符型编号 from YourTable where 日期型字段=''''''+FormatDateTime(''yyyy-MM-dd'',now)+''''''''; 也等价于: 等价于: adoquery1.sql.text:= ''select 字符型编号 from YourTable where 日期型字段=''+QuotedStr(FormatDateTime(''yyyy-MM-dd'',now)); 传到服务器为: select 字符型编号 from YourTable where 日期型字段=''2003-12-01'' 日期字段还可以这样表示 Delphi语句 adoquery1.sql.text:= ''select 字符型编号 from YourTable where 日期型字段>=''+QuotedStr(FormatDateTime(''yyyy-MM-dd'',now)) +'' and 日期型字段<=''+QuotedStr(FormatDateTime(''yyyy-MM-dd'',now+1));//明天 等价于 adoquery1.sql.text:= ''select 字符型编号 from YourTable where 日期型字段 between ''+QuotedStr(FormatDateTime(''yyyy-MM-dd'',now)) +'' and ''+QuotedStr(FormatDateTime(''yyyy-MM-dd'',now+1)); 如果用 adoquery1.sql.add(); 形式又如何操作?请用Insert语句示例 adoquery1.sql.add('' insert into ''+AtableName); adoquery1.sql.add('' ( ''+AFieldName+'')''); adoquery1.sql.add('' values( ''+quotedstr(AStr)+'')'');
编辑器加载中...
相关文章推荐
- 总结一下SQL语句中引号(')、quotedstr()、('')、format()在SQL语句中的用法
- 总结一下SQL语句中引号(')、quotedstr()、('')、format()在SQL语句中的用法
- 总结一下SQL语句中引号(')、quotedstr()、('')、format()在SQL语句中的用法
- 总结一下SQL语句中引号(')、quotedstr()、('')、format()在SQL语句中的用法
- (转载)总结一下SQL语句中引号(')、quotedstr()、('')、format()在SQL语句中的用法
- SQL语句中引号(')、quotedstr()、('')、format()在SQL语句中的用法
- 总结一下delphi中SQL语句中引号
- 总结一下SQL语句中引号
- 总结一下最近实践上用到的sql语句
- 6 Django系列之关于models的sql语句日常用法总结
- 【MYSQL】基础SQL语句总结(三)筛选记录基本用法
- Oracle的sql语句中case关键字的用法 & 单双引号的使用
- SQL语句 事务的用法性质总结
- servlet 中sql语句的双引号和单引号的用法
- mybatis中SQL语句单双引号的问题java.lang.NumberFormatException: For input string: "Y"
- SQL Server 的动态语句(SQLServer 的String.format用法)(SQLServer的调用SQL占位符的使用)
- vb中sql语句的单引号和双引号的用法
- 【总结】alter table *** add constraint *** 用法 . 建立约束 ,主键、外键的SQL语句写法
- vb中sql语句的单引号和双引号的用法
- sql语句中where的引号用法