Access 与 sql server 语法差异
Access SqlServer
系统时间
Date()
getdate
()
见 10 点
连接字符串
& +
截取字符串
Mid
SubString
见 20 点
小写字符串
LCase
Lower
见 12 点
大写字符串
UCase
Upper
见 12 点
条件取值
IIF
Case
+
When
+
Else
见 17 点
字段类型转换
CStr
,
CInt
,
CDate
Convert
或
cast
见 21 点
日期字符串
#2011-08-10#
'2011-08-10'
见 4 点
1、
select,update 语句区别
select,update 对于单表操作时基本一致。
但多表操作时
Access 与 SqlServer 中的
update
语句会有差别:
SqlServer 中更新多表的
update
语句:
update
Table1
set
a
.
Name
=
b
.
Name
from
Table1 a
,
Table2 b
where
a
.
ID
=
b
.
ID
;
Access 中同样功能的
sql 语句:
update
Table1 a
,
Table2 b
set
a
.
Name
=
b
.
Name
where
a
.
ID
=
b
.
ID
;
比较得出:
Access 中的
update
语句没有
from
子句
,所有引用的表都列在
update
关键字后
2、delete 语句
SqlServer 中:
delete
from
<
表名>
where
ID
>
1
;
Access 中:
delete
*
from
<
表名>
where
ID
>
1
;
3、as 后面的计算字段区别
SqlServer 中:
select
sum
(
num
)
as
sum_num
,
sum
(
num
)*
num
as
all_num
from
<
表名>
;
Access 中:
select
sum
(
num
)
as
sum_num
,
sum_num
*
num
as
all_num
from
<
表名>
;
比较得出:
SqlServer 中:不可以把
as
后的字段当作一个数据库字段参与计算。
Access 中: 可以把
as
后的字段当作一个数据库字段参与计算。
SQL
Server
as
可以省略,Access 不能
4、
时间字段、日期分隔符号
SqlServer 中:单引号(’)
select
*
from
<
表名>
where
RegDate
=
'
2011-08-10
'
Access中:
要用#号分隔,转换为日期
select
*
from
<
表名>
where
生日
=
#2011
-
08
-
10#
select
*
from
<
表名>
where
生日
=
2011
-
08
-
10
select
*
from
<
表名>
where
生日
=
CDate
(
#2011
-
08
-
10#)
select
*
from
<
表名>
where
生日
=
CDate
(
2011
-
08
-
10)
select
*
from
<
表名>
where
生日
=
CDate
(
'2011-08-10'
)
5、Boolean 所表示的常量
SqlServer 中:整数:1(真)、0(假)