溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

Access與sql server語(yǔ)法的區(qū)別是什么

發(fā)布時(shí)間:2021-07-26 16:09:21 來(lái)源:億速云 閱讀:167 作者:Leah 欄目:數(shù)據(jù)庫(kù)

今天就跟大家聊聊有關(guān)Access與sql server語(yǔ)法的區(qū)別是什么,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

日期分隔符號(hào)
  access:英鎊符(#)
  sql server:撇號(hào)(')

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

字符串連接
  access:和號(hào)(&)
  sql server:加號(hào)(+)

通配符
  access:星號(hào)(*)與零個(gè)或更多字符匹配。 
      問(wèn)號(hào)(?)與單個(gè)字符匹配。
      嘆號(hào)(!)意味著不在列表中。
      英鎊符(#)意味著單個(gè)數(shù)字。
  sql server:百分號(hào)(%)與零個(gè)或更多字符匹配。 
      下劃線(xiàn)(_)與單個(gè)字符匹配。
      上插入符(^)意味著不在列表中。
      沒(méi)有與英鎊符(#)對(duì)應(yīng)的字符。

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

表添加標(biāo)識(shí)列
  access:alter table <表名> add <列名> Counter(1,1)
  sql server:alter table <表名> add <列名> bigint identity(1,1) not null

一、有區(qū)別的函數(shù)及解決方案 

以下所示的解決方案中的函數(shù)定義在untDataBase單元中TAdoConn類(lèi)的方法中。

號(hào)簡(jiǎn)述Access語(yǔ)法SqlServer語(yǔ)法Oracle語(yǔ)法DB2語(yǔ)法解決方案
01系統(tǒng)時(shí)間Date()GETDATE()SYSDATE GetSysTimeStr
02連接字符串&+||+GetConcatStr
03截取字符串 SubString
 
SubStr
 
SubStringSubStringGetSubStr
04小寫(xiě)字符串LCaseLowerLowerLowerGetLowerStr
05大寫(xiě)字符串UCaseUpper
 
Upper
 
Upper
 
GetUpperStr
06查找字符串InStr
 
InStr
 
CharIndex
 
InStr
 
GetFindStr
07替換空值IIF+IsNullCoalesce
 
NvlCoalesceGetNullStr
08條件取值IIFCase+When+ElseDeCode或Case
 
IIF
 
GetCaseStr
09字段類(lèi)型轉(zhuǎn)換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語(yǔ)句函數(shù)Like ‘101*Like ‘101%'
 
Like ‘101%'
 
 GetLikeStr
       

二、Access與SQLSERVER部分相同數(shù)據(jù)庫(kù)函數(shù)及關(guān)鍵字列表

1、 函數(shù)

序號(hào)
 
簡(jiǎn)述 
01記數(shù)函數(shù)
 
Count
02最大值Max
   

2、 關(guān)鍵字

序號(hào)
 
簡(jiǎn)述 
01
 
Like
02連接Join
03判斷空Is Null
   

三、Access與語(yǔ)句SqlServer的語(yǔ)句語(yǔ)法區(qū)別 
1、 Inser Into …..Select …From 語(yǔ)句:
在ACCESS中以下語(yǔ)句 
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')"中的小括號(hào)("(",")")必須去掉才能執(zhí)行,如下: 
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 語(yǔ)句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 +''''; 
應(yīng)該改為 
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 +''''; 
該行代碼的檢索條件錯(cuò)誤:應(yīng)該把C.copy_id=C.Copy_id 改為c.copy_id=d.copy_id 
注:兩種寫(xiě)法都能在SQL-SERVER中運(yùn)行,但c.copy_id=C.copy_id在ACCESS中不能運(yùn)行 
3、 Inner Join 語(yǔ)句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+ ''''; 
注:兩種寫(xiě)法都能在SQL-SERVER中運(yùn)行,但第一種在ACCESS中不能運(yùn)行 
4、 Inner Join語(yǔ)句3 

SQl server 中可以執(zhí)行以下語(yǔ)句 
'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語(yǔ)句 

Sql SerVer 中能執(zhí)行但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個(gè)函數(shù)“GetDateStr” 
7、 最大數(shù)值獲取語(yǔ)句 
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'+'''' 
注:兩種寫(xiě)法都能在SQL-SERVER中運(yùn)行,但第一種在ACCESS中不能運(yùn)行 
但是考慮會(huì)出現(xiàn)Null值以及語(yǔ)句的通用性,可以使用以上的第07個(gè)函數(shù)“GetNullStr”和第09個(gè)函數(shù)“GetConvertStr”來(lái)完成字符串向數(shù)字,空值和0數(shù)字的轉(zhuǎn)換:參考GetNextNumStr代碼。

看完上述內(nèi)容,你們對(duì)Access與sql server語(yǔ)法的區(qū)別是什么有進(jìn)一步的了解嗎?如果還想了解更多知識(shí)或者相關(guān)內(nèi)容,請(qǐng)關(guān)注億速云行業(yè)資訊頻道,感謝大家的支持。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI