(转载)总结一下SQL语句中引号(')、quotedstr()、('')、format()在SQL语句中的用法
2013-10-24 17:28
627 查看
总结一下SQL语句中引号(')、quotedstr()、('')、format()在SQL语句中的用法 |
总结一下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 语句的limit的用法(转载)
- [转载]SQL基本语句用法(用ADO连接数据库用的)
- [转载]Oracle中SQL语句的几种用法
- SQL Server 的动态语句(SQLServer 的String.format用法)(SQLServer的调用SQL占位符的使用)
- [转载]SQL语句---nvl 用法
- vb中sql语句的单引号和双引号的用法
- sql 语句的limit的用法(转载)
- servlet 中sql语句的双引号和单引号的用法
- sqlite3的sql语句用法总结与SQLite生成.db-journal文件问题
- vb中sql语句的单引号和双引号的用法
- 【总结】alter table *** add constraint *** 用法 . 建立约束 ,主键、外键的SQL语句写法
- 动态sql语句用法实例:SQL Server2000下验证(部分转载)