我在學習專門連接到SQL並提取一些帳戶詳細信息的VBA腳本。但是,我得到一個語法錯誤「關鍵字‘加入’附近語法錯誤。你能幫我找到語法錯誤。VBA中的語法錯誤「JOIN」
strQuery = "" _
& "DECLARE @Perns TABLE(Id INT)" _
& " INSERT INTO @Perns (Id)" _
& " SELECT 4098 " _
& " SELECT ddm.FirstName, ddm.LastName, am.alias AS Alias, ddm.PersonnelNbr AS N'Pern#', nam.parent_OU_DN, gc.PersonGroupDesc AS N'AccManNG Status' " _
& " FROM @Perns AS p" _
& "LEFT OUTER JOIN [Accmanng].[dbo].[directory_data_master] ddm ON p.Id=ddm.PersonnelNbr" _
& "LEFT OUTER JOIN [Accmanng].[dbo].[alias_master] am ON am.alias_id = ddm.alias_id" _
& "LEFT OUTER JOIN [Accmanng].[dbo].[network_account_master] nam ON AM.alias_id = nam.alias_id" _
& "LEFT OUTER JOIN [Accmanng].[dbo].[dim_groupcode] gc ON ddm.PersonGroupCode=gc.PersonGroupCode " _
& "WHERE ddm.PersonnelNbr in (SELECT Id FROM @perns)"
rst.Open strQuery, ConnectString
Sheets(1).Range("A2").CopyFromRecordset rst
什麼是'N'Pern#''和'N'AccManNG Status''? –
'LEFT'之前還有空嗎? –
它改變了列名稱,這只是讓它更容易閱讀。這樣當我們複製標題時已經標記了Headers。 – RyanWilliamWest