本文為大家簡單整理了access與sql server的語法區(qū)別,希望對大家有所幫助。
一、有區(qū)別的函數(shù)及解決方案?
以下所示的解決方案中的函數(shù)定義在untDataBase單元中TAdoConn類的方法中。
二、Access與sqlserver部分相同數(shù)據(jù)庫函數(shù)及關(guān)鍵字列表
1、 函數(shù)
2、 關(guān)鍵字
三、Access與語句SqlServer的語句語法區(qū)別
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’)”中的小括號(“(“,”)”)必須去掉才能執(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 語句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 +””;
該行代碼的檢索條件錯誤:應(yīng)該把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 中可以執(zhí)行以下語句
‘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 中能執(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
+’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
+’and end_date>=#’+datetostr(LoginDate)+’#’
參考以上的第10個函數(shù)“GetDateStr”
7、 最大數(shù)值獲取語句
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中不能運行
但是考慮會出現(xiàn)NULL值以及語句的通用性,可以使用以上的第07個函數(shù)“GetNullStr”和第09個函數(shù)“GetConvertStr”來完成字符串向數(shù)字,空值和0數(shù)字的轉(zhuǎn)換:參考GetNextNumStr代碼。
1、Sql中不能省略as?
2、一次只能執(zhí)行一條Sql?
3、沒有substring、cast等函數(shù)?
4、sql中嚴格區(qū)分整形和字符型?
5、沒有存儲過程、觸發(fā)器?
6、!= 替換為?
7、時間字符串兩邊加#號
8、帶參數(shù)的sql語句中 @用?號替換
相關(guān)推薦:access數(shù)據(jù)庫教程