本文为大家简单整理了access与sql server的语法区别,希望对大家有所帮助。
一、有区别的函数及解决方案
以下所示的解决方案中的函数定义在untDataBase单元中TAdoConn类的方法中。
二、Access与SQLSERVER部分相同数据库函数及关键字列表
1、 函数
2、 关键字
三、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代码。
1、Sql中不能省略as
2、一次只能执行一条Sql
3、没有substring、cast等函数
4、sql中严格区分整形和字符型
5、没有存储过程、触发器
6、!= 替换为<>
7、时间字符串两边加#号
8、带参数的sql语句中 @用?号替换
相关推荐:access数据库教程
以上是access与sql server的语法对比的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能

SublimeText3 Linux新版
SublimeText3 Linux最新版

Dreamweaver Mac版
视觉化网页开发工具