dreamscapeuk
Programmer
Hi,
I'm fairly new to VBScript and I've bene trying really hard to pick it up over the last few weeks to get my project completed. Basically we load data from oracle to essbase and I wanted to create something to validate the data. I'm trying to pul data from Oracle and put it in an easy format that would be easy for VBScript to read when I later ask it to read values from 2 files and flag any differences.
I've managed to connect to Oracle and run the query but I am only getting it to write the account and balance for the first line. I've tried so many methods and am obviously doing something wrong. I'd prefer to get it into an array and then write it to file so I can create a couple of files. 1 with just account and balance and the other with the full report. I tried the array method bu tthen can't gget it to write to a file! Any help will be most appreciated. I'm trying to learn VB as I'm doing this so comments would be really useful
Here's my file so far:
dbType?=?"oracle"?????????????????'?Database?type
dbHost?=?"10.10.10.10"?????????????????'?Hostname?of?the?database?server
dbName?=?"ABCD"?????????????????'?Name?of?the?database/SID
dbUser?=?"xxxx"???????????????'?Name?of?the?user
dbPass?=?"XXXXX"???????????????'?Password?of?the?above-named?user
'*?Define?Constants?/?Variables
Const?SQLquery?=?"Select?sob.name?set_of_book,bal.period_name,
gcc.segment1?le,gcc.segment2?cc,gcc.segment3?acct,gcc.segment5?prod,gcc.segment6?mu,
gcc.segment7?ic,?
bal.currency_code,
to_char(SUM((bal.period_net_dr?-?bal.period_net_cr)))?period_balance?
FROM?GL.GL_BALANCES?bal,GL.GL_CODE_COMBINATIONS?gcc,?
GL.GL_SETS_OF_BOOKS?sob?
WHERE??bal.code_combination_id?=?1149165?
AND?bal.period_name?in?(to_char(add_months(sysdate,-1),'MON-YY'))
AND?gcc.summary_flag?=?'N'?AND????bal.set_of_books_id?=?sob.set_of_books_id?AND????bal.currency_code?=?sob.currency_code?AND????sob.name?=?'AZ_CON_USD'?AND????bal.actual_flag?=?'A'?GROUP??BY?sob.name,?
bal.period_name,?
gcc.segment1,?
gcc.segment2,?
gcc.segment3,?
gcc.segment5,?
gcc.segment6,?
gcc.segment7,?
bal.currency_code?HAVING?SUM((bal.PERIOD_NET_DR?-?bal.PERIOD_NET_CR))?!=?0"????????
set?Conn?=?CreateObject("ADODB.connection")
Dim?rows:?Set?rows?=?CreateObject("ADODB.Recordset")
Conn.ConnectionTimeout?=?30
Conn.CommandTimeout?=?30
Dim?connectionString:?ConnectionString?=?"Provider=OraOLEDB.Oracle;User?ID="?&?dbUser?&?";Password="?&?dbPass?&?";Data?Source="?&?dbName?&?";Persist?Security?Info=False"
'*?Create?objects
Dim?WshShell
Set?WshShell?=?CreateObject("WScript.Shell")
Dim?fso
Set?fso?=?CreateObject("Scripting.FileSystemObject")
'*?Create?log?file
Dim?LogFile
Set?ResultsFile?=?fso.CreateTextFile("Results.log",?true)
'*?Open?connection
Conn.Open?connectionString
WScript.Echo?"Retrieving?SQL?Data"
'*?Execute?SQL
rows.Open?SQLquery,?Conn,?0,?1??
????rows.MoveFirst
????????Do?Until?rows.EOF
????????????ResultsFile.WriteLine?rows.Fields("ACCT")?&?vbTab?&?rows.Fields("PERIOD_BALANCE")
????rows.MoveNext
??
Loop
????
????WScript.Echo?"Completed,?closing?connections"
????
'*?Close?log?file
LogFile.Close
'*?Close?connection?and?clean?up?objects
Conn.Close
Set?rows?=?Nothing
Set?Conn?=?Nothing
Set?WshShell?=?Nothing
Set?fso?=?Nothing
Set?LogFile?=?Nothing
Set?ResultsFile?=?Nothing
**************Many thanks***************
I'm fairly new to VBScript and I've bene trying really hard to pick it up over the last few weeks to get my project completed. Basically we load data from oracle to essbase and I wanted to create something to validate the data. I'm trying to pul data from Oracle and put it in an easy format that would be easy for VBScript to read when I later ask it to read values from 2 files and flag any differences.
I've managed to connect to Oracle and run the query but I am only getting it to write the account and balance for the first line. I've tried so many methods and am obviously doing something wrong. I'd prefer to get it into an array and then write it to file so I can create a couple of files. 1 with just account and balance and the other with the full report. I tried the array method bu tthen can't gget it to write to a file! Any help will be most appreciated. I'm trying to learn VB as I'm doing this so comments would be really useful
Here's my file so far:
dbType?=?"oracle"?????????????????'?Database?type
dbHost?=?"10.10.10.10"?????????????????'?Hostname?of?the?database?server
dbName?=?"ABCD"?????????????????'?Name?of?the?database/SID
dbUser?=?"xxxx"???????????????'?Name?of?the?user
dbPass?=?"XXXXX"???????????????'?Password?of?the?above-named?user
'*?Define?Constants?/?Variables
Const?SQLquery?=?"Select?sob.name?set_of_book,bal.period_name,
gcc.segment1?le,gcc.segment2?cc,gcc.segment3?acct,gcc.segment5?prod,gcc.segment6?mu,
gcc.segment7?ic,?
bal.currency_code,
to_char(SUM((bal.period_net_dr?-?bal.period_net_cr)))?period_balance?
FROM?GL.GL_BALANCES?bal,GL.GL_CODE_COMBINATIONS?gcc,?
GL.GL_SETS_OF_BOOKS?sob?
WHERE??bal.code_combination_id?=?1149165?
AND?bal.period_name?in?(to_char(add_months(sysdate,-1),'MON-YY'))
AND?gcc.summary_flag?=?'N'?AND????bal.set_of_books_id?=?sob.set_of_books_id?AND????bal.currency_code?=?sob.currency_code?AND????sob.name?=?'AZ_CON_USD'?AND????bal.actual_flag?=?'A'?GROUP??BY?sob.name,?
bal.period_name,?
gcc.segment1,?
gcc.segment2,?
gcc.segment3,?
gcc.segment5,?
gcc.segment6,?
gcc.segment7,?
bal.currency_code?HAVING?SUM((bal.PERIOD_NET_DR?-?bal.PERIOD_NET_CR))?!=?0"????????
set?Conn?=?CreateObject("ADODB.connection")
Dim?rows:?Set?rows?=?CreateObject("ADODB.Recordset")
Conn.ConnectionTimeout?=?30
Conn.CommandTimeout?=?30
Dim?connectionString:?ConnectionString?=?"Provider=OraOLEDB.Oracle;User?ID="?&?dbUser?&?";Password="?&?dbPass?&?";Data?Source="?&?dbName?&?";Persist?Security?Info=False"
'*?Create?objects
Dim?WshShell
Set?WshShell?=?CreateObject("WScript.Shell")
Dim?fso
Set?fso?=?CreateObject("Scripting.FileSystemObject")
'*?Create?log?file
Dim?LogFile
Set?ResultsFile?=?fso.CreateTextFile("Results.log",?true)
'*?Open?connection
Conn.Open?connectionString
WScript.Echo?"Retrieving?SQL?Data"
'*?Execute?SQL
rows.Open?SQLquery,?Conn,?0,?1??
????rows.MoveFirst
????????Do?Until?rows.EOF
????????????ResultsFile.WriteLine?rows.Fields("ACCT")?&?vbTab?&?rows.Fields("PERIOD_BALANCE")
????rows.MoveNext
??
Loop
????
????WScript.Echo?"Completed,?closing?connections"
????
'*?Close?log?file
LogFile.Close
'*?Close?connection?and?clean?up?objects
Conn.Close
Set?rows?=?Nothing
Set?Conn?=?Nothing
Set?WshShell?=?Nothing
Set?fso?=?Nothing
Set?LogFile?=?Nothing
Set?ResultsFile?=?Nothing
**************Many thanks***************