Access与sql server语法的区别是什么

发布时间:2021-07-26 16:09:21 作者:Leah
来源:亿速云 阅读:155

今天就跟大家聊聊有关Access与sql server语法的区别是什么,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

日期分隔符号
  access:英镑符(#)
  sql server:撇号(')

Boolean 常量
  access:True、False;On、Off;Yes、No;整数:-1(真)、0(假)。
  sql server:整数:1(真)、0(假)

字符串连接
  access:和号(&)
  sql server:加号(+)

通配符
  access:星号(*)与零个或更多字符匹配。 
      问号(?)与单个字符匹配。
      叹号(!)意味着不在列表中。
      英镑符(#)意味着单个数字。
  sql server:百分号(%)与零个或更多字符匹配。 
      下划线(_)与单个字符匹配。
      上插入符(^)意味着不在列表中。
      没有与英镑符(#)对应的字符。

DROP INDEX
  access:Drop Index <索引名> ON <表名>
  sql server:Drop Index <表名>.<索引名>

表添加标识列
  access:alter table <表名> add <列名> Counter(1,1)
  sql server:alter table <表名> add <列名> bigint identity(1,1) not null

一、有区别的函数及解决方案 

以下所示的解决方案中的函数定义在untDataBase单元中TAdoConn类的方法中。

简述Access语法SqlServer语法Oracle语法DB2语法解决方案
01系统时间Date()GETDATE()SYSDATE GetSysTimeStr
02连接字符串&+||+GetConcatStr
03截取字符串 SubString
 
SubStr
 
SubStringSubStringGetSubStr
04小写字符串LCaseLowerLowerLowerGetLowerStr
05大写字符串UCaseUpper
 
Upper
 
Upper
 
GetUpperStr
06查找字符串InStr
 
InStr
 
CharIndex
 
InStr
 
GetFindStr
07替换空值IIF+IsNullCoalesce
 
NvlCoalesceGetNullStr
08条件取值IIFCase+When+ElseDeCode或Case
 
IIF
 
GetCaseStr
09字段类型转换Str、var、….Convert或cast
 
To_Char,To_Number.GetConvertStr
 
GetConvertStr
10日期字符串
 
‘2004-10-9'
 
#2004-10-19#
 
‘2004-10-9' GetDateStr
11最大值加1
 
    GetNextNumStr
12Like语句函数Like ‘101*Like ‘101%'
 
Like ‘101%'
 
 GetLikeStr
       

二、Access与SQLSERVER部分相同数据库函数及关键字列表

1、 函数

序号
 
简述 
01记数函数
 
Count
02最大值Max
   

2、 关键字

序号
 
简述 
01
 
Like
02连接Join
03判断空Is Null
   

三、Access与语句SqlServer的语句语法区别 
1、 Inser Into …..Select …From 语句:
在ACCESS中以下语句 
Insert INTO 
PubSubJectAccCopys(Copy_id,Acc_id,Acc_Pid,Acc_name,acc_short,Acc_Comment,Acc_Pro,acc_type,Sub_id_flag,acc_index) (Select 200201,Acc_id,Acc_Pid,Acc_name,acc_short,Acc_Comment,Acc_Pro,acc_type,Sub_id_flag,acc_index FROM PubSubJectAcc Where PubSubJectAcc.co_type='03') 
中后面"(select 200201******.co_Type='03')"中的小括号("(",")")必须去掉才能执行,如下: 
Insert INTO 
PubSubJectAccCopys(Copy_id,Acc_id,Acc_Pid,Acc_name,acc_short,Acc_Comment,Acc_Pro,acc_type,Sub_id_flag,acc_index) Select 200201,Acc_id,Acc_Pid,Acc_name,acc_short,Acc_Comment,Acc_Pro,acc_type,Sub_id_flag,acc_index FROM PubSubJectAcc Where PubSubJectAcc.co_type='03' 
在SQL SERVER 中都可以 
2、 Inner Join 语句1 

StrSql:='select a.user_id,a.user_opcode,b.copy_name from sysuser a inner join (syscopysuser c inner join syscopys b on c.copy_id=c.copy_id) on a.user_id=c.user_id where 
a.user_opcode=''' +EdtUserOpCode.text+''' And copy_name='''+Tmpcopyname +''''; 
应该改为 
StrSql:='select a.user_id,a.user_opcode,b.copy_name from sysuser a inner join (syscopysuser c inner join syscopys b on c.copy_id=d.copy_id) on a.user_id=c.user_id where 
a.user_opcode=''' +EdtUserOpCode.text+''' And copy_name='''+Tmpcopyname +''''; 
该行代码的检索条件错误:应该把C.copy_id=C.Copy_id 改为c.copy_id=d.copy_id 
注:两种写法都能在SQL-SERVER中运行,但c.copy_id=C.copy_id在ACCESS中不能运行 
3、 Inner Join 语句2 
StrSql:='select copy_year,copy_name,a.copy_id from SysCopys a inner join SysCopysUser b on a.curcopy_flag=1 and a.copy_id=b.copy_id where b.user_id=' + '''' +TmpPubUserID+ ''''; 
该为 
StrSql:='select copy_year,copy_name,a.copy_id from SysCopys a inner join SysCopysUser b on a.copy_id=b.copy_id where a.curcopy_flag=''1'' and b.user_id=' + '''' +TmpPubUserID+ ''''; 
注:两种写法都能在SQL-SERVER中运行,但第一种在ACCESS中不能运行 
4、 Inner Join语句3 

SQl server 中可以执行以下语句 
'Select distinct sysoption.opti_id,sysoption.opti_name,sysoption.opti_code,sysroleoption.opti_sort From sysoption inner join sysroleoption ON sysoption.opti_id=sysroleoption.opti_id AND sysroleoption.role_id=:roleid' 
但ACCESS中不能,只能 
'Select distinct sysoption.opti_id,sysoption.opti_name,sysoption.opti_code,sysroleoption.opti_sort From sysoption inner join sysroleoption ON sysoption.opti_id=sysroleoption.opti_id Where sysroleoption.role_id=:roleid' 
5、 Update语句 

Sql SerVer 中能执行但Access 中不能 
'Update sysuserrole SET sysuserrole.role_sort = (Select sysrole.role_sort FROM sysrole Where sysuserrole.role_id = sysrole.role_id and sysuserrole.user_id='01')' 
6、 日期比较 

SQL SERVER 中用 
StrSql:='select copy_year,Start_month,Cur_month,Start_Flag,Start_date,End_date ' 
+'From SysCopys ' 
+'where copy_id='''+LoginCopyID+''' ' 
+'and start_date<='''+datetostr(LoginDate)+''' ' 
+'and end_date>='''+datetostr(LoginDate)+''''; 
ACCESS中用 
StrSql:='select copy_year,Start_month,Cur_month,Start_Flag,Start_date,End_date ' 
+'From SysCopys ' 
+'where copy_id='''+LoginCopyID+''' ' 
+'and start_date<=#'+datetostr(LoginDate)+'# ' 
+'and end_date>=#'+datetostr(LoginDate)+'#' 
参考以上的第10个函数“GetDateStr” 
7、 最大数值获取语句 
StrSql:='insert into sysRoleOption ' 
+'select '''+fidRoleId+''' as Role_ID,opti_id,' 
+'convert(numeric,opti_id)-(convert(numeric,opti_parentid)*100)+'+ MaxOptiSort 
+' as opti_Sort from sysoption where opti_parentid=''' 
+PCoTypeID(self.trvRoles.Selected.data)^.StrCoTypeID 
+''' and opti_bottom=''1'+''''; 
改为 
StrSql:='insert into sysRoleOption ' 
+'select '''+fidRoleId+''' as Role_ID,opti_id,' 
+'opti_id-opti_parentid*100+'+ MaxOptiSort 
+' as opti_sort from sysoption where opti_parentid=''' 
+PCoTypeID(self.trvRoles.Selected.data)^.StrCoTypeID 
+''' and opti_bottom=''1'+'''' 
注:两种写法都能在SQL-SERVER中运行,但第一种在ACCESS中不能运行 
但是考虑会出现Null值以及语句的通用性,可以使用以上的第07个函数“GetNullStr”和第09个函数“GetConvertStr”来完成字符串向数字,空值和0数字的转换:参考GetNextNumStr代码。

看完上述内容,你们对Access与sql server语法的区别是什么有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。

推荐阅读:
  1. sql和sql server有什么区别
  2. sql server、mysql的定义以及区别

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

access sqlserver

上一篇:MySQL中如何使用mysqldump命令

下一篇:SQL Server中怎么访问Sybase中的表

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》