运行时错误' -2147217900(80040e14)':' 1'附近的语法不正确

时间:2017-07-11 15:27:21

标签: sql sql-server vba excel-vba excel

同事正在休假,我正在为他报道SQL报告等。需要帮助查看他的代码并弄清楚它失败的原因。此代码位于Excel-VBA中,并从SQL Server Management Studio中提取。如您所见,某些代码已被注释掉。任何帮助将不胜感激。

Function queryData(strSQL As String, ByRef objDB As Object)
    'v1.0 - 2006.11.17 - Jaes W Overley (JO3945)
    'v1.1 = 2013.08.26 - Jaes W Overley (JO3945)
    'v1.2 - 2015.08.11 - Mark Waters
    Dim objField As Object, objRS As Object
    Dim lngCol As Long
    Dim strConnect As String
    Dim results As Variant
    Dim emptyarray(0 To 2, 0 To 0) As String
    emptyarray(0, 0) = ""
    emptyarray(1, 0) = ""
    emptyarray(2, 0) = ""
    'Set objDB = New ADODB.Connection
    Set objRS = New ADODB.Recordset

    'used to have connect here - commented out so we only connect once when we run more than one query
    'If Not CONNECTED(strConnect) Then Exit Function

    'Open Database
    'objDB.Open strConnect
    objRS.Open strSQL, objDB
    'Add Field Headers
    'For Each objField In objRS.Fields
    '    lngCol = lngCol + 1
    '    With .Cells(1, lngCol)
    '        .Value = UCase(objField.Name)
    '        .Font.Bold = True
    '        .Font.Color = vbWhite
    '        .Interior.Color = vbBlue
    '    End With
    'Next
    If Not objRS.EOF Then
        results = objRS.GetRows
    Else
        results = emptyarray
    End If
    objRS.Close
    'objDB.Close
    queryData = results
End Function

这是SQL代码:

select 
    envPkgs.Client_Mnemonic
    , envPkgs.Environment 
    , PkgInfo.OCD_Number 
    , envPkgs.Install_Date_Time
    , PkgInfo.Name 
    , pkginfo.External_Solution_Name 
    , PkgInfo.Type_String 
    , CASE WHEN testedPkgs.sts ='Tested' THEN 'Tested' 
        WHEN awarePkgs.sts = 'Aware' THEN 'Aware' 
        Else 'Needs Review' END AS 'Status'
from MSA_Package_Install_Summary envPkgs with (nolock) 
join OCD_Base_Data PkgInfo with (nolock) 
    on envPkgs.OCD_Number = PkgInfo.OCD_Number 
left join ( VALUES ('IHC_UT', 86993, 'Tested'), ('IHC_UT', 72826, 'Tested'), ('IHC_UT', 83972, 'Tested'), ('IHC_UT', 87465, 'Tested'), ('BRMC_IA', 87345, 'Tested'), ('BRMC_IA', 86713, 'Tested'), ('BRMC_IA', 87374, 'Tested'), ('BRMC_IA', 84724, 'Tested'), ('IHC_UT', 87391, 'Tested') 
, ('IHC_UT', 86133, 'Tested'), ('IHC_UT', 86132, 'Tested'), ('IHC_UT', 86131, 'Tested'), ('IHC_UT', 86128, 'Tested'), ('IHC_UT', 86126, 'Tested'), ('IHC_UT', 86125, 'Tested'), ('IHC_UT', 86124, 'Tested'), ('IHC_UT', 86123, 'Tested'), ('IHC_UT', 86122, 'Tested'), ('IHC_UT', 86121, 'Tested') 
, ('IHC_UT', 84544, 'Tested'), ('RUTL_VT', 85684, 'Tested'), ('RUTL_VT', 84159, 'Tested'), ('RUTL_VT', 82963, 'Tested'), ('RUTL_VT', 86993, 'Tested'), ('RUTL_VT', 86805, 'Tested'), ('RUTL_VT', 86795, 'Tested'), ('RUTL_VT', 86794, 'Tested'), ('RUTL_VT', 86793, 'Tested'), ('RUTL_VT', 86792, 'Tested') 
, ('RUTL_VT', 86804, 'Tested'), ('UNIV_MO', 86972, 'Tested'), ('UNIV_MO', 86952, 'Tested'), ('UNIV_MO', 83038, 'Tested'), ('UNIV_MO', 82950, 'Tested'), ('UNIV_MO', 87691, 'Tested'), ('UNIV_MO', 66422, 'Tested'), ('YAVA_AZ', 84958, 'Tested'), ('YAVA_AZ', 86204, 'Tested'), ('YAVA_AZ', 86993, 'Tested') 
, ('YAVA_AZ', 86068, 'Tested'), ('AGNE_WI', 835321-10434458131, 'Tested'), ('AGNE_WI', 84416, 'Tested'), ('AGNE_WI', 86305, 'Tested'), ('AGNE_WI', 85772, 'Tested'), ('AGNE_WI', 83647, 'Tested'), ('AGNE_WI', 86949, 'Tested'), ('AGNE_WI', 84459, 'Tested'), ('AGNE_WI', 86095, 'Tested'), ('AGNE_WI', 86052, 'Tested') 
, ('AGNE_WI', 84920, 'Tested')) AS testedPkgs (mnem, pkg, sts)
    on testedPkgs.mnem = envPkgs.Client_Mnemonic and testedPkgs.pkg = PkgInfo.OCD_Number 
left join ( VALUES ('IHC_UT', 86993, 'Aware'), ('IHC_UT', 72826, 'Aware'), ('IHC_UT', 83972, 'Aware')) AS awarePkgs (mnem, pkg, sts)
    on awarePkgs.mnem = envPkgs.Client_Mnemonic and awarePkgs.pkg = PkgInfo.OCD_Number 
left join MSA_Package_Install_Summary dupe with (nolock) 
    on dupe.Client_Mnemonic = envPkgs.Client_Mnemonic
    and dupe.OCD_Number = envPkgs.OCD_Number
    and dupe.Install_Date_Time < envPkgs.Install_Date_Time
where 
    envPkgs.Client_Mnemonic IN ('AGNE_WI', 'AH_MO', 'AHMO_CT', 'AHMO_ET', 'ARMC_GA', 'BH_AL', 'BRMC_IA', 'CARE_RH', 'CERN_CLIN' 
, 'CERN_RWX', 'CHAR_NC', 'CHI_CO', 'CHI_CO', 'CHW_CA', 'CHWB_CA', 'CRVN_NC', 'LEID_VA', 'EAST_AL', 'EJEF_LA' 
, 'EXCL_PA', 'GHS_IA', 'GLEN_NY', 'IHC_UT', 'JACK_FL', 'LAC_CA', 'LMH_KS', 'MCGH_GA', 'NAPL_FL', 'NKCMH_MO' 
, 'NMHS_NE', 'PHA_SC', 'QEMR_AU', 'RUTL_VT', 'SGEN_OH', 'THCH2_TX', 'THCH5_TX', 'THCH6_TX', 'TRUM_MO', 'UCQS_AU' 
, 'UMC_TX', 'UNIV_MO', 'YAVA_AZ')
    and envPkgs.Install_Date_Time >= getDate() - 7
    and dupe.Client_Mnemonic IS NULL
Order by 
    envPkgs.Install_Date_Time desc

1 个答案:

答案 0 :(得分:0)

SQL的这部分内容

('AGNE_WI', 835321-10434458131, 'Tested')  

-10434458131似乎不属于。