ADO-SQL-Excel

G

Guest

How can I execute this instruction TRANSACT-SQL with ADO in Excel and then
export it to excel. It is like a record but made with TRANSACT-SQL.
Is it posible???

Select Sum(contdiar.importe*contdiam.tasa * Case When contdiar.debito= 1
Then 1 Else -1 End )
From ContDiam Inner Join ContDiar on ContDiam.Id_Diam = ContDiar.Id_Diam
Where ...

JC.
 
G

Guest

What you call 'instruction' is your SQL statement. Try:

set adors = createobject("ADODB.Recordset")
adors.Open 'your SQL statement' , 'the connnection string to SQL server DB'

Now lok up CopyFromREcordSet in the Excel help files to transfer adors to a
worksheet; your SQL statement must return less than 65536 rows and less than
256 columns.
 
W

witek

JC. said:
How can I execute this instruction TRANSACT-SQL with ADO in Excel and then
export it to excel. It is like a record but made with TRANSACT-SQL.
Is it posible???

Select Sum(contdiar.importe*contdiam.tasa * Case When contdiar.debito= 1
Then 1 Else -1 End )
From ContDiam Inner Join ContDiar on ContDiam.Id_Diam = ContDiar.Id_Diam
Where ...

JC.

I post a link to Microsoft site a few weeks ago, how to do this.
Try to find it.
ADO is not a T-SQL, but most of things can be done.
There is a bug in ADO which doesn't not allow to work on open files.
So if you want to read on write to the same file as your code it will
not work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top