title: Incorrect Syntax Error "JOIN" in VBA
body: <p>I'm trying to learn VBA Script specifically connecting to SQL and pulling a few account details. However, I'm getting a syntax error "Incorrect Syntax near the keyword 'Join'. Could you help me find the syntax error. </p>
  
  <pre><code>        strQuery = "" _
                          &amp; "DECLARE @Perns TABLE(Id INT)" _
                          &amp; " INSERT INTO @Perns (Id)" _
                          &amp; " SELECT 4098 " _
                          &amp; " SELECT ddm.FirstName, ddm.LastName, am.alias AS Alias, ddm.PersonnelNbr AS N'Pern#', nam.parent_OU_DN, gc.PersonGroupDesc AS N'AccManNG Status' " _
                          &amp; " FROM @Perns AS p" _
                          &amp; "LEFT OUTER JOIN [Accmanng].[dbo].[directory_data_master] ddm ON p.Id=ddm.PersonnelNbr" _
                          &amp; "LEFT OUTER JOIN [Accmanng].[dbo].[alias_master] am ON am.alias_id = ddm.alias_id" _
                          &amp; "LEFT OUTER JOIN [Accmanng].[dbo].[network_account_master] nam ON AM.alias_id = nam.alias_id" _
                          &amp; "LEFT OUTER JOIN [Accmanng].[dbo].[dim_groupcode] gc ON ddm.PersonGroupCode=gc.PersonGroupCode " _
                          &amp; "WHERE ddm.PersonnelNbr in ( SELECT Id FROM @perns)"
  
  
      rst.Open strQuery, ConnectString
  
  
      Sheets(1).Range("A2").CopyFromRecordset rst
  </code></pre>