November 16, 2007 at 4:16 am
Hi,
How can I run a code line from Excel, without opening SQL Server 2005 and executing the command???
Let's suppose that I want to run the following code: select * from Tbl1
Thanks
November 16, 2007 at 4:39 am
In Excel There is one Option called Import External Data in the Data Tab In the Main Menu, Make use of One Data Source to Connect with the server.
November 16, 2007 at 4:51 am
Thanks vinuraj, but I was thinking in something more like using VBA code to run the code line in SQL and retrieve the result. Is this possible???
Thanks
November 16, 2007 at 6:11 am
Yes it is, but there's far more to it than a quick post to the forums.
But something like this should get you started.
Private Sub yourSubroutine()
Set con = CreateObject(“adodb.connection”)
Set rs = CreateObject(“adodb.recordset”)
con.Open “Provider=sqloledb; Data Source=db-serv;Initial Catalog=yourDB; User Id=admin; Password=admin;”
rs.Open “select * from yourTable?, con
i = 2
Do While Not rs.EOF
Cells(i, 2) = rs(“yourColumn”)
rs.movenext
i = i + 1
Loop
rs.Close
Set rs = Nothing
Set con = Nothing
End Sub
For more detailed info, I suggest googleing "VBA, SQL and Excel"
______________________________________________________________________
Personal Motto: Why push the envelope when you can just open it?
If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.
Jason L. SelburgNovember 16, 2007 at 7:17 am
Thanks Jason Selburg but there is any book where I can find what I need??
Thank you again
November 16, 2007 at 7:23 am
Sure, there are a ton of them.
Do search on amazon.com
______________________________________________________________________
Personal Motto: Why push the envelope when you can just open it?
If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.
Jason L. SelburgViewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply