1. 查询Where条件带布尔类型值(条件语句):
Access(版本2003) and IsA = true ; (不含引号)
Sql server and IsA =1 或 IsA ='true'
3:多分支的判断情况:
Access(版本2003以上) : select Switch(isBuy =false,‘A’,isBuy = true,'B') as ColName from 表
或 select iif(OpenPrice is null,0,aa) as A from 表
Sql server : select Case when then else end as ColName as A from 表
4. 将字符类型转换成数值类型。
Access 中 , val(Num)
SQL Server 中, Convert(int,Num)或 Cast(Num as int)
6.格式化成多日期。(不用采用 Format(date,'Short Date') 月/日部分会出现位数)
Access : Format(date,'yyyy-MM-dd') between '2015-11-17' and '2015-11-17'
Sql Server : Convert(varchar(20),TimeTag,23) between '2015-11-17' and '2015-11-17'
Access : Format(date,'yyyy-MM-dd hh:mm:ss') //时分秒
SQl server: Convert(varchar(20),TimeTag,120) //时分秒
7.当前从Access 数据库导入的SQl Server 中时,原表中的自增长列会丢失, 需要重新建立标示列。
8.导入到 Sql server时 Access 的数据如存在密码则 以独立的方式 清空Access原设置的密码。
9. 参数化更新或新增数据时,SQl 语句中的字段顺序需与参数列表的顺序保持一致(避免更新错误)
如: update A set Column =@Name,Age = @Age wehre ID =@ID
OleParameter osp =new OleParameter []
{
new OleParemeter("@Name",model.Name),
new OleParemeter("@Age",model.Age),
new OleParemeter("@ID",model.ID),
}
11.关于Access日期条件的查询。
-- SELECT * FROM Quantize where TimeTag = Format('2016-1-6','yyyy-MM-dd hh:mm:ss')
--或格式 SELECT * FROM Quantize where TimeTag = Format("2016-1-6","yyyy-MM-dd hh:mm:ss")
12.尽量使用: string Sql = String.Format("{0},{1}", args);
13.类似于SQl server 的函数 IsNULL().
--1.字符串类型
select iif(列1='' or 列1 is null,'',列1) + 列2 as 列1_f
--2.数值类型的转换函数。
select str(数值列) as 列1_f from 表
14.创建表或添加列时,附带 默认约束(Defualt)
15. 创建新列时未添加默认约束时,采用内置函数 str(A) 查询时会显示null值(Access)
如下:
alter table 表 add A varchar(23)
select iif(str(A) is null,'空','非空') from 表