我正在尝试学习专门连接到SQL并提取一些帐户详细信息的VBA脚本。但是,我在关键字'加入'附近收到语法错误"错误的语法。你能帮我找到语法错误吗?
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
答案 0 :(得分:3)
您在JOIN子句
之前缺少空格$(document).ready(function(){
var offsetTop = $('.row-floating').offset().top;
var actualWidth =$('.row-floating').width();
$(window).scroll(function() {
if( window.pageYOffset >= offsetTop){
$('.row-floating').css('position', 'fixed').css('top', 0).css('width',actualWidth);
} else {
$('.row-floating').css('position', 'relative').css('top', 'auto').css('width','auto');
}
});
});
编辑:戈登也抓到了一些问题。我很确定你得到的错误是因为加入附近的空间。
答案 1 :(得分:1)
打印出你的代码。 20个中大约19次使错误显而易见。
代码的前几行是:
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)"
这不是有效的SQL:
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'
. . .