Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default put query result into variable

hi hope someone can help
i can connect to oracle through excel no problem
the problem i am having is i want to put the result of the following query
into a varable
at the moment i return the result into a cell on a excel worksheet then use
the value in the cell for a second query
here is the query i use

Sub form_a()
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim sql As String
Dim col As Integer
Dim data_to_find As Variant
Dim cttab As String

cnn.Open "Driver={microsoft odbc for oracle};" & _
"Server=EASY ;" & _
"Uid=easy;" & _
"Pwd=easy;"




sql = " select distinct code"
sql = sql & " from history"
sql = sql & " where trunc(date_time) = trunc(sysdate-1)"
rst.Open sql, cnn, adOpenKeyset, adLockReadOnly
Cells(1, 1).Select
ActiveCell.CopyFromRecordset rst
cttab = "CT_" & Cells(1, 1).Value

rst.Close

sql = " select brand from " & cttab & " "
sql = sql & " where trunc(calldate) = trunc(sysdate-1)"
sql = sql & " and brand is not null"
rst.Open sql, cnn, adOpenKeyset, adLockReadOnly


Cells(1, 1).Select
ActiveCell.CopyFromRecordset rst
rst.Close


End Sub



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default put query result into variable

Depending on if you expect one or more rows your would do:

dim vVar

vVar = rst.GetRows

or

vVar = rst.Fields(0)


RBS


"andy" wrote in message
...
hi hope someone can help
i can connect to oracle through excel no problem
the problem i am having is i want to put the result of the following query
into a varable
at the moment i return the result into a cell on a excel worksheet then
use the value in the cell for a second query
here is the query i use

Sub form_a()
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim sql As String
Dim col As Integer
Dim data_to_find As Variant
Dim cttab As String

cnn.Open "Driver={microsoft odbc for oracle};" & _
"Server=EASY ;" & _
"Uid=easy;" & _
"Pwd=easy;"




sql = " select distinct code"
sql = sql & " from history"
sql = sql & " where trunc(date_time) = trunc(sysdate-1)"
rst.Open sql, cnn, adOpenKeyset, adLockReadOnly
Cells(1, 1).Select
ActiveCell.CopyFromRecordset rst
cttab = "CT_" & Cells(1, 1).Value

rst.Close

sql = " select brand from " & cttab & " "
sql = sql & " where trunc(calldate) = trunc(sysdate-1)"
sql = sql & " and brand is not null"
rst.Open sql, cnn, adOpenKeyset, adLockReadOnly


Cells(1, 1).Select
ActiveCell.CopyFromRecordset rst
rst.Close


End Sub




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a value from a variable result Darren Excel Discussion (Misc queries) 1 April 19th 10 06:43 PM
Replace ^ in web query result Don Guillett Excel Worksheet Functions 0 April 26th 06 03:42 PM
Importing result from Access query to Excel but the result only c. Edwin Excel Discussion (Misc queries) 0 March 16th 06 01:36 AM
Formula Result Won't Query natei6 Excel Discussion (Misc queries) 3 November 24th 05 06:20 AM
Passing SQL Query Result Into A Variable Elliot[_2_] Excel Programming 4 January 9th 04 09:55 AM


All times are GMT +1. The time now is 09:12 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"