AW: OraSession Oracleinprocserver
01.09.2020 15:13:33
peterk
Hallo
Sollte so ähnlich funktionieren
Sub neu()
' Microsoft ActiveX Data Object 2.n Library must be referenced
Dim conDB As ADODB.Connection ' Connection Object
Dim rsRows As ADODB.Recordset ' DB Recordset
Dim strConnect As String ' Connect-String
strConnect = "Provider=OraOLEDB.Oracle" & _
";Data Source=" & "appdbprod" & _
";User Id=" & "maskxxx" & _
";Password=" & "maskxxxpw"
' Make the Connection
Set conDB = New ADODB.Connection ' New Instance of Connection
conDB.ConnectionString = strConnect ' Set the ConnectionString in Object
conDB.Open strConnect ' Connect to the Database
' Open Recordset and execute SQL
Set rsRows = New ADODB.Recordset ' New Instance of Recordset
rsRows.CursorLocation = adUseClient ' Set the CursorLocation-Attribute
SEL = "C.CODE,A.TYP"
SOU1 = "MASKDBA.AKTIVE_MASKEN A, "
SOU2 = "MASKDBA.RETICLES B, "
SOU3 = "MASKDBA.MASK_LOCATIONS C "
SOU = SOU1 & SOU2 & SOU3
con = "A.ID=B.ID_MASK and B.ID_LOCATION=C.ID and B.AKTIV = 1 and (C.CODE='N' or C.CODE='E' _
or C.CODE='I' or C.CODE='K' or C.CODE='Q' or C.CODE='T')"
DBQuery = "select " & SEL & " from " & SOU & " where " & con & ";"
rsRows.Open Source:=DBQuery, ActiveConnection:=conDB, _
CursorType:=adOpenStatic, LockType:=adLockOptimistic
' copy whole recordset to a table, just for testing
'Worksheets("Tabelle1").Cells(1, 1).CopyFromRecordset rsRows
While Not rsRows.EOF
For j = 0 To rsRows.Fields.Count - 1
If j = 0 Then
Loc = rsRows.Fields(j).Value
If Loc = "N" Then C1 = C1 + 1
If Loc = "E" Then C2 = C2 + 1
If Loc = "I" Then C3 = C3 + 1
If Loc = "K" Then C4 = C4 + 1
If Loc = "Q" Then C5 = C5 + 1
If Loc = "T" Then C6 = C6 + 1
' If X1 = 2 Then C8 = C8 + 1
End If
Next j
rsRows.MoveNext
i = i + 1
Wend
End Sub