Anda di halaman 1dari 12

Creating Configuration Manager 2007 Reports

Part I – Basics
Kent Agerlund - 7th September 2008

I often hear customers and students complaining about the complexity of creating reports. Statements like;
“the database is a mystery” and “I am not a SQL expert. I agree, the database can be a mystery. But using the
proper tools and some very basic SQL skills you will be able to create powerful reports.

I will post 4 parts explaining the basics and how to build a few reports.

Views:
Reports are based on SQL views. A view is basically just a query joining one or more tables. Knowing a few
basics of the naming standard I very helpful:

V_GS_Name = Contains current inventory data


V_HS_Name = Contains history inventory data
V_R_Name = Contains Scalar Discovery data.
V_RA_Name = Contains Array (Multi value) Discovery data.

SQL Server Management Studio:


I use SQL Server Management Studio to create the reports. It’s a nice graphical interface and I can easily test
the syntax.

Conditionals:
SQL uses well-known conditionals like:
<
>
=
AND
OR
NOT
DISTINCT
LIKE
TOP
Aggregate Functions:
GROUP BY
COUNT
MIN
MAX
Part II – Creating first Report
In this part I will walk you through the creation of a report in SQL Server Managmenet Studio. The report will
show all clients with SMS 2003 Toolkit installed.

Open SQL Server Management Studio and log on to


the server.

Navigate to the Configuration Manager database. The


name is most likely SMS_<Sitecode>.

Right click Views and select New View

Select the Views tab.

Add V_R_System and V_GS_Add_Remove_Programs

Note: V_R_System contains the basic discovery data.

Now when we have the views we must create an Inner


Join.From V_R_System drag the column RessourceID
onto the RessourceID column onto the
V_GS_Add_Remove_Programs view
Select Netbios_Name() from V_R_System and
DisplayName() from V_GS_Add_Remove_Programs.
In the Criteria pane type SMS 2003 Toolkit and press
enter in the Filter cell for the DisplayName()
column.Notice that SQL automatically will replace the
text with =’SMS 2003 Toolkit’ – Nice
Let’s view the result before we copy the statement to
Configuration Manager.Make sure that the SQL and
Results panes are visible. If not right click, select Pane
and enable them.

If everything looks OK; copy the entire SQL statement.

Open the Configuration Manager console and navigate to


Reporting. Click New in the Actions pane.

In name type: All Computers with SMS 2003 Toolkit


installedIn Category type: <Company name>
SoftwareIn comment type the date, your name and a
short description of the content.

Click Edit SQL Statement. Highlight the default SQL


statement, right click and Paste your SQL statement into
the Window.
Click OK.

Click Next.

Click Next.

Click Next.
Click Next.

Click Close.

Click Close – Congratulations you survived the wizard

Highlight your report and click Run in the Actions pane.

You have now created your first report – it’s time to go


impress management
Part III – Using Count
In this example I explain how to use the Count function. I anticipate that you already by now know how to
create the report in Configuration Manager and how to start SQL Server Management Studio. This report will
group all computer objects by Vendor and Model with a count of each unique model.

  I’ve started SQL Server Management Studio, navigated to the


SMS_Sitecode database, and created a new View. For information about
those steps please refer to Part II of this post.
Select V_GS_Computer_System, click Add and Close.

Select the columns Manufacturer(), Model() and Model() - the Model


column is selected twice as we need the one column with a name and the
second column with a count.

In Alias type Total for the second Model() column.


From the Query Designer menu, select Add Group By.

Select Count in the second Model() column. Your SQL statement should
look like this:

SELECT     Manufacturer0, Model0, COUNT(Model0) AS Total


FROM         dbo.v_GS_COMPUTER_SYSTEM
GROUP BY Manufacturer0, Model0
Execute the SQL Statement. The result from my test environment is
displayed in the left column. Now copy the SQL statement to a new
report in Configuration Manager as explained in Part II of this post.

Part IV – Using Prompt


In this example I explain how to use the prompt function. I anticipate that you already by now know how to
create the report in Configuration Manager and how to start SQL Server Management Studio. This report will
list some basic hardware details with a prompt on the Bios Serial number. I am creating the first part of the
report in SQL server 2008 Studio Manager, and the prompt in the Config Mgr. console.

When you are working with prompts in reports there is a few things you need to know first.

 To use variables use the @ symbol eg. WHERE V_GS_PC_BIOS.SerialNumber0 = @BiosSerialNumber


 Variables in SQL statement stores the values from the prompt

The following views are used in this example:

V_R_SYSTEM

V_GS_PC_BIOS
V_GS_COMPUTER_SYSTEM

  I’ve started SQL Server Management Studio, navigated to the


SMS_Sitecode database, and created a new View. For information
about those steps please refer to Part II of this post.
Select V_GS_Computer_System, V_R_SYSTEM, V_GS_PC_BIOS
click Add and Close.

From V_R_System drag the column RessourceID onto the


RessourceID column onto the  V_GS_Computer_System view.

From V_R_System drag the column RessourceID onto the


RessourceID column onto the  V_GS_PC_BIOS view.

From V_R_SYSTEM select, Name()


From V_GS_PC_BIOS select, Name(), Releasedate(),
SerialNumber()
From V_GS_COMPUTER_SYSTEM select, Manufacturer0,
Model0, NumberOfProcessors0

In the V_GS_PC_BIOS.Name()  Alias. column type Bios Name


The SQL statement:
SELECT     dbo.v_R_System.Name0, dbo.v_GS_COMPUTER_SYSTEM.Manufacturer0,
dbo.v_GS_COMPUTER_SYSTEM.Model0,
                      dbo.v_GS_COMPUTER_SYSTEM.NumberOfProcessors0, dbo.v_GS_PC_BIOS.Name0 AS [Bios
Name], dbo.v_GS_PC_BIOS.ReleaseDate0,
                      dbo.v_GS_PC_BIOS.SerialNumber0
FROM         dbo.v_R_System INNER JOIN
                      dbo.v_GS_COMPUTER_SYSTEM ON dbo.v_R_System.ResourceID =
dbo.v_GS_COMPUTER_SYSTEM.ResourceID INNER JOIN
                      dbo.v_GS_PC_BIOS ON dbo.v_R_System.ResourceID = dbo.v_GS_PC_BIOS.ResourceID

The Result

Copy the SQL statement, open the Config Mgr. console, create a new
report and paste the SQL statement as explained in post II.

If you finish the report wizard, you will have a useful report with basic
hardware information.

Now you need to create the prompt and the select statement. We start
by creating the prompt, click on the Prompts button.

In the Prompts dialog box click on the yellow starburst icon (to create
a new prompt)

In the Name column type the variable name (this is the name we will
use later in the Where statement). In my example I type
BiosSerialNumber

In prompt text type the text that will be displayed for the end user. I
typed Select bios serial number
Next we will provide a SQL statement which will fill the list of bios
serial numbers.
Click Provide a SQL statement and click the Edit SQL Statement
button

In the SQL statement box type:


Select distinct SerialNumber0 From v_GS_PC_BIOS

Click OK

Click OK

Click OK
Click Yes

By now you should be back in the SQL statement, navigate to the end
and type
WHERE     (dbo.v_GS_PC_BIOS.SerialNumber0 =
@BiosSerialNumber)

Notice: You could also type @BiosSerialNumber  in the criteria


column in SQL Server Management Studio.

Click OK and save the report.

When you run the report it should look like this.

When you click Values you will run the SQL statement from the
prompt

Click Display
Nice report

Anda mungkin juga menyukai