Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Scripted Server Snapshot


Scripted Server Snapshot

Author
Message
rscarlson
rscarlson
Valued Member
Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)

Group: General Forum Members
Points: 54 Visits: 6
Comments posted to this topic are about the content posted at http://www.sqlservercentral.com/columnists/rcarlson/scriptedserversnapshot.asp



rscarlson
rscarlson
Valued Member
Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)

Group: General Forum Members
Points: 54 Visits: 6
Regarding the problem with outputing to Word. The DBName has nulls. We used an If..Then to detect the Null, and output "no db" else the name of the database. If anyone is interested I can e-mail the code.



hot2use
hot2use
SSC-Enthusiastic
SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)

Group: General Forum Members
Points: 163 Visits: 71

And adding a short inputbox for the server is cool if your centrally managing multiple servers.

[...]
Dim i
Dim srvname

srvname = InputBox ( "Enter the Server Name", "Server", "xxxxxx")

' making the connection to your sql server
' change yourservername to match your server
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")

' this is using the trusted connection if you use sql logins
' add username and password, but I would then encrypt this
' using Windows Script Encoder
objConnection.Open _
"Provider = SQLOLEDB;Data Source=" & srvname & " ;" & _
"Trusted_Connection=Yes;Initial Catalog=Master;"
[...]

And this little addition formats the CPUTime column so that you can sort the column afterwards:

[...]
objExcel.Cells(i, 7).Value = FormatNumber(objRecordset.Fields.Item("CPUTime"), 0, -1, 0, 0)
[...]

Otherwise a cool piece of code. I don't have the time to get into coding much these days, but that might change.

Thanks

hot2use




__________________________________
Searching the KB articles is like
picking your nose. You never know
what you'll find.

RobertPaquette
RobertPaquette
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 Visits: 628
I called objRecordSet rs and objWorksheet ws,
but it seems like you could just do something like this

For CurCol = 0 To rs.Fields.Count - 1: ws.Cells(1, CurCol + 1).Value = rs.Fields(CurCol).Name: Next
ws.Range("A2").CopyFromRecordset rs



Kenneth Lee
Kenneth Lee
SSC Journeyman
SSC Journeyman (81 reputation)SSC Journeyman (81 reputation)SSC Journeyman (81 reputation)SSC Journeyman (81 reputation)SSC Journeyman (81 reputation)SSC Journeyman (81 reputation)SSC Journeyman (81 reputation)SSC Journeyman (81 reputation)

Group: General Forum Members
Points: 81 Visits: 1
Why do you have the banner (row 1) cells defined in the loop?
RobertPaquette
RobertPaquette
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 Visits: 628
Just as the column names, for use with pivot tables. I use this code to automate reporting to excel. A few lines of code hoses the data to excel & refreshes all the pivot tables & graphs in the workbook...



rscarlson
rscarlson
Valued Member
Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)

Group: General Forum Members
Points: 54 Visits: 6

Great ideas. Thanks.





rscarlson
rscarlson
Valued Member
Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)

Group: General Forum Members
Points: 54 Visits: 6

You can remove the titles from the loop.





F Vandeputte
F Vandeputte
SSC-Enthusiastic
SSC-Enthusiastic (118 reputation)SSC-Enthusiastic (118 reputation)SSC-Enthusiastic (118 reputation)SSC-Enthusiastic (118 reputation)SSC-Enthusiastic (118 reputation)SSC-Enthusiastic (118 reputation)SSC-Enthusiastic (118 reputation)SSC-Enthusiastic (118 reputation)

Group: General Forum Members
Points: 118 Visits: 59

Hi,

This is really a nice script. I made a few changes. Now it works with any SELECT statement or stored proc.

I posted the code on my blog:

http://users.telenet.be/frederik.vandeputte/blog/2005/07/anyquery2excelvbs.html

Kind regards,

Frederik


RobertPaquette
RobertPaquette
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 Visits: 628
you can replace the entire second loop with 1 command:

objWorksheet.Range("A2").CopyFromRecordset objRecordSet



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search