Co-worker is on sabbatical and I am covering for him for SQL Reports and such. Need help looking at his code and figuring out why it is failing. This code is in Excel-VBA and pulling in from SQL Server Management Studio. As you can see, some of the code is commented out. Any help would be appreciated.
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
Here is the SQL code:
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
This part of your SQL looks off
('AGNE_WI', 835321-10434458131, 'Tested')
That -10434458131
doesn't seem to belong.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.