< Blog

How to Create a Prompted Query (WQL)

By Garth Jones

Not too long ago, I answered a question within the ConfigMgr 2012 forums about why a prompted query wasn’t working. This led me to write a blog post about how to create a prompted query.

Creating a prompted query (or WQL) is similar to creating any other query, so I won’t provide every step, only the basics.

NOTE: I’m using ConfigMgr 2012 in my example, but the steps are basically the same for 2007 and 2016.

Create a Prompted Query - Step 1

1. Open the ConfigMgr 2012 console and browse to Monitoring | Queries. Next, click on the Create Query button.

Create a Prompted Query - Step 2

2. Provide a Name for your query and then click on Edit Query Statement…

Create a Prompted Query - Step 3

3. Select the displayed columns that you want to see. Next, click on the Criteria tab.

Create a Prompted Query - Step 4

4. This is where the fun begins. Click the star Create a Prompted Query - Star Button button.

Create a Prompted Query - Step 5

Create a Prompted Query - Prompted Value

5. Change the Criterion Type to Prompted value from the drop-down box.

Now, finish creating the query as you would any other query, but before clicking on OK take a look at the next screenshot to make sure your results are similar.

Create a Prompted Query - Step 6 

6. When you are finished adding the Prompted value criteria, it should look similar to the screenshot above. Now, click OK.

The final query (watch for word wrapping) will look like this:

select

                SMS_R_System.NetbiosName,

                SMS_R_System.LastLogonUserName,

                SMS_R_System.OperatingSystemNameandVersion

from 

                SMS_R_System

where

                SMS_R_System.OperatingSystemNameandVersion like #PRM:SMS_R_System.OperatingSystemNameandVersion##

Create a Prompted Query - Step 7

7. When you run the query you will be prompted for a value.

Note: Make sure to include the “%” sign when using a Like as your operator within the query.

Create a Prompted Query - Step 8 

8. Finally, this is what the results of your query should look like.

If you have any questions, please send me a tweet @GarthMJ.