Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 800A0E78 problem

Author  Topic 

jparker
Posting Yak Master

118 Posts

Posted - 2004-12-13 : 09:11:18
I am creating a WSH script which uses a rather complex SQL statement. For some reason just with this SQL statement and no other I get the 800A0E78 error - "Operation is not allowed when the object is close" - when I check the status of oRS.State its at 0.

I just can't see where I am going wrong as the SQL statement works fine in query analyzer.



sSQL = "create table #Quoted ( " &_
" job_id int, " &_
" supplier_id int, " &_
" quoted decimal(10,2), " &_
" po_id int) " &_
"insert into #Quoted " &_
" (job_id,supplier_id,quoted,po_id) " &_
" select job_id, p.supplier_id, sum(cost) as 'quoted' ,po_id " &_
" from tblPurchaseorder p " &_
" where " &_
" job_id in (" &_
" select distinct si.job_id from tblSalesInvoice si, tblEstimate e " &_
" where " &_
" si.est_id=e.est_id " &_
" and si.invoiceDate between GetDate()-60 and GetDate()) " &_
" and (p.dateFullyInvoiced is null or p.dateFullyInvoiced >= GetDate()) " &_
" group by job_id,p.supplier_id,po_id " &_
" create table #Invoiced (" &_
" job_id int, " &_
" supplier_id varchar(20), " &_
" su_code varchar(20), " &_
" invoiced decimal(10,2), " &_
" po_id int) " &_
" insert into #Invoiced " &_
" (job_id,supplier_id,su_code,invoiced,po_id) " &_
" select job_id, supplier_id, su_code, " &_
" sum(case type " &_
" when 'I' then valuenet " &_
" when 'C' then -valuenet " &_
" end) " &_
" as 'invoiced' ,po_id " &_
" from tblPurchaseInvoice " &_
" where job_id in (select distinct si.job_id from tblSalesInvoice si, tblEstimate e " &_
" where " &_
" si.est_id=e.est_id " &_
" and si.invoiceDate between GetDate()-60 and GetDate())" &_
" and po_id in (select po_id from tblPurchaseOrder where " &_
" dateFullyInvoiced is null or dateFullyInvoiced >= GetDate()) " &_
" and invoiceDate between GetDate()-60 and GetDate() " &_
" group by job_id,supplier_id, su_code,po_id " &_
" select q.job_id,Quoted, isnull(invoiced,0) as 'invoiced', " &_
" (Quoted-isnull(invoiced,0)) as 'accrual', " &_
" s.supplier_code, s.supplier_name,e.title " &_
" from #Quoted q " &_
" left outer join #invoiced i " &_
" on (q.job_id=i.job_id AND q.supplier_id=i.supplier_id and q.po_id=i.po_id) " &_
" join tblsupplier s " &_
" on (s.supplier_id=q.supplier_id) " &_
" join tblestimate e " &_
" on (e.job_id=q.job_id) " &_
" where (Quoted-isnull(invoiced,0))<>0 " &_
" order By q.job_id,s.supplier_name " &_
" drop table #Quoted " &_
" drop table #Invoiced "
set oRs=CreateObject("ADODB.recordset")
mydsn = "********************"
oRs.Open sSQL, mydsn, 3, 3 ' adOpenStatic and adLockOptimistic are ideal cursor for a recordcount.
wsh.echo oRS.State

Wanderer
Master Smack Fu Yak Hacker

1168 Posts

Posted - 2004-12-13 : 09:31:34
hmm ... back of my mind, I get a warning bell about the size of the SQL statement. There is a max size...

ahh:
The maximum size of a single Embedded SQL statement is 8,191 characters for 16-bit Microsoft® Windows® 2000

Looks like you could be ok on that, though...

*##* *##* *##* *##*

Chaos, Disorder and Panic ... my work is done here!
Go to Top of Page

MichaelP
Jedi Yak

2489 Posts

Posted - 2004-12-13 : 09:45:31
Put a SET NOCOUNT ON at the top of your SQL Script, and then a SET NOCOUNT OFF at the bottom and see how that works for ya.

Michael

<Yoda>Use the Search page you must. Find the answer you will.</Yoda>
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2004-12-13 : 10:02:03
Why aren't you writing this as a stored procedure and then calling the procedure from your script?
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-12-13 : 10:06:30
Ummm...Create a stored procedure instead?



Brett

8-)
Go to Top of Page

jparker
Posting Yak Master

118 Posts

Posted - 2004-12-13 : 10:21:16
Hello all,

Thanks for your help. I would have loved to have done a stored procedure but unfortunately the database in administered by a third party at present so I can't add any additional code. Very frustrating.

Thank you to MichaelP though the SET NOCOUNT On/Off worked like a charm.

Thanks agains

JP
Go to Top of Page
   

- Advertisement -