The below SQL which is in the code will get the value from Sheet2.Range("C2") field and will execute the query.
My requirement is i have values in Sheet2.C3, Sheet2.C4, Sheet2.C5 and it goes on till there is a Blank Cell.
I would like the SQL to pick up the value in Sheet2.C3, Sheet2.C4 one by one and execute the query (It should stop once it finds a NULL value).
SQL:
select DT_KEY from dt_dim where CAL_DT = TO_DATE('" & Sheet2.Range("C2").Value & "', 'MM/DD/YYYY')
Sheet2:
Image.jpg
Kindly help me in the same
Sub Ora_Connection()
Dim sourceCnn As ADODB.Connection
Dim sourceRst As ADODB.Recordset
Set sourceCnn = New ADODB.Connection
Set sourceRst = New ADODB.Recordset
strCon = "Provider=OraOLEDB.Oracle;User ID=;Password=;Data Source="
sourceCnn.Open (strCon)
sourceRst.ActiveConnection = sourceCnn
sourceRst.Source = "select DT_KEY from dt_dim where CAL_DT = TO_DATE('" & Sheet2.Range("C2").Value & "', 'MM/DD/YYYY')"
sourceRst.Open
Sheets("Sheet2").Select
Cells(lastrow, 1).Select
Do While Not sourceRst.EOF
Selection.Offset(1, 1) = sourceRst.Fields("DT_KEY")
Selection.Offset(1, 0).Select
sourceRst.MoveNext
Loop
sourceRst.Close
End Sub
Bookmarks