13
、Access中的逻辑值在库中为
-
1
和0
,
而SQL
Server
中为1和0
,
所以写BoolField
=
1
这样的语句
有兼容性问题,应该改为BoolField
<>
0
14
、Access的
varchar
(文本)型最大只有255,所以如果一个文本型字段大于255时,最好定义成备
注型(Access中)或
text
型(SQL
Server
中);
15.
ACCESS 所有类型为:
Big
Integer
、
Binary
、Boolean、Byte、
Char
、Currency、Date
/
Time
、
Decimal
、
Double
、
Flo
at
、GUID、Integer、Long、Long
Binary
(
OLE
Object
)
、Memo、
Numeric
、Single、
Text
、
Time
、
TimeStamp
、
VarBinary
。
常用的几种:
Date
/
Time
日期
/
时间
Boolean
是
/
否
Decimal
小数
Memo
备注
Text
文本
Integer
整数
如果用自动编号且主键,如下:
create
table
table1
(
id autoincrement
(
1
,
1
)
primary
key
)
create
table
AAA
(
RID Counter
,
url Memo
,
ActName Memo
,
ActDate
text
(
150
),
Up_Time
text
(
100
))
连接字符串:conn =
"Provider = Microsoft.Jet.OLEDB.4.0;Data Source = database.mdb"
;
16.
随机读取若干条记录
SqlServer:
select
top
5
*
from
<
表名>
order
by
newid
();
Access:
select
top
5
*
From
<
表名>
ORDER
BY
Rnd
(
id
);
17.
条件取值
IIF
Case
+
When
+
Else
的使用
使用 SQL 语句用
...
代替过长的字符串显示
SqlServer:
select
case
when
len
(
列名)>
10
then
left(
列名,
10
)+
'...'
else
列名
end
as
别名
from
表名;
Access:
select IIF(
len
(
列名)>
2
,left(
列名,
2
)+
'...'
,
列名
) from
表名;
18.
余数
Access
:
a mod b
SqlServer
:
a
%
b
19.
判断字段值为空的区别
普通空:
Access
和
SqlServer
一样
where
code
is
null
或
where
code
is
not null
条件空:
Access
:iif
(
列名 is
null,
0
,
列名)
或iif
(
列名 is
null,
列名2, 列名)
SqlServer
:
isnull
(
列名,
0
)
或
isnull
(
列名, 列名 2)
20. 截取字符串
Access:
select
Mid
(
列名,
2
,
4
)
from
<
表名>;
SqlServer:
select
substring
(
列名,
2
,
4
)
from
<
表名>;