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 2005 Forums
 SQL Server Administration (2005)
 Exporting data from queries

Author  Topic 

scooternm
Starting Member

8 Posts

Posted - 2008-07-09 : 12:07:41
This is been driving me crazy! I have a Word document that I was hoping to import data based on queries I have written. For example, there may be a sentence in my Word doc that says:

'There was 784 logs found.' In this example, is there a way to import the 784 (variable) from SQL. I have written the query that would return 784 (or whatever the result is). The Word doc has a ton of variables like this so if I can somehow pull right from SQL it would help me out a lot. I haven't found anything to indicate this is possible. If not, any other ideas?

mfemenel
Professor Frink

1421 Posts

Posted - 2008-07-09 : 12:51:10
Not a great solution but you might tinker with it. You could create a database query using excel and then embed that excel object into your word document. with some work on the formatting you could probably make it seamless.

Mike
"oh, that monkey is going to pay"
Go to Top of Page

scooternm
Starting Member

8 Posts

Posted - 2008-07-09 : 12:57:21
Yeah, that's kind of what I was thinking and it would probably work for this. What I did what basically created a spreadsheet of imported data from SQL...so Column A in my spreadsheetcontained all the data I will want to pull into Word.

I'm running into the same problem though...I really don't know how to have word pull in a particular cell value from an Excel sheet. I know I am kind of venturing off the purpose of this site now, but does anyone happen to know any resources where I can find out how to do this (besides copy,paste)

Thanks!
Go to Top of Page

mfemenel
Professor Frink

1421 Posts

Posted - 2008-07-09 : 13:11:26
I'm use an archaic version of Word right now but I wonder if you might be able to shred some xml in a word doc instead of using embedded excel. You could spit that out from sql and then parse it in your word doc. Just a thought, I have no tools to try that theory.

Mike
"oh, that monkey is going to pay"
Go to Top of Page

scooternm
Starting Member

8 Posts

Posted - 2008-07-09 : 15:16:50
Thanks for the suggestion. I'll play around with it and report back. I figured this would be a fairly common request and being in the same MS family, this would be easy. Oh well.

Scott
Go to Top of Page

jwise
Starting Member

3 Posts

Posted - 2008-07-09 : 15:50:13
I've written several Excel macros which send data to Word files. I've also written Excel macros which retrieve values from SQL. I see no problem with retrieving a single value and sending it to Word. I have written a few Word macros, but I do not know how to do a SQL query directly in Word. I suggest you look at www.vbaexpress.com. This is my favorite VBA reference.
Go to Top of Page

scooternm
Starting Member

8 Posts

Posted - 2008-07-09 : 16:21:41
Thanks. I think simple creating Word template and then using Copy (in Excel), Paste Special (in Word) will work for me.

Anyway slightly off topic for this forum... thanks both of you for your advice and help.

Scott
Go to Top of Page
   

- Advertisement -