Solved

Modify output results of SQL 2005 query

Posted on 2011-03-16
5
317 Views
Last Modified: 2012-05-11
Hello. My environment is MS SQL 2005 SP3. I am trying to figure out a way to modify the results of a query. My query works correctly (query below). However, I would like to display anything with a null value in BitLocker_Enabled0, TPM_On0 and TPM_Activated0 as False. Currently, it says null when there is no value.

Would Case When give me the results? So far, I cannot get it to work properly.

Right now, the results look like the below.

US                    FDS22      user1      Latitude E6400             NULL        NULL      NULL
US                    FDS24      user2      Latitude E6400             NULL        NULL      NULL
US                    FDS25      user15      Latitude E6410       True        True              True

I want it to look like

US                    FDS22      user1      Latitude E6400             False        False      False
US                    FDS24      user2      Latitude E6400             False        False      False
US                    FDS25      user15      Latitude E6410       True        True              True
SELECT     sys.AD_Site_Name0, sys.Name0, sys.User_Name0, cs.model0 AS Model, bit.BitLocker_Enabled0 AS 'BitLocker Enabled', bit.TPM_On0 AS 'TPM On', 
                      bit.TPM_Activated0 AS 'TPM Activated', bit.Script_Last_Run0 AS 'Last Time Script was Run'
FROM         v_GS_BitLocker_TPM_Info0 AS bit INNER JOIN
                      v_R_System AS sys ON bit.ResourceID = sys.ResourceID INNER JOIN
                      v_GS_COMPUTER_SYSTEM as cs ON sys.ResourceID = cs.ResourceID
WHERE		(sys.Operating_System_Name_and0 = 'Microsoft Windows NT Workstation 6.1') AND (cs.Model0 LIKE '%Latitude%') OR
			(sys.Operating_System_Name_and0 = 'Microsoft Windows NT Workstation 6.1') AND (cs.Model0 LIKE '%Precision M%')
ORDER BY sys.AD_Site_Name0

Open in new window

0
Comment
Question by:Lorrec
5 Comments
 
LVL 24

Expert Comment

by:jimyX
ID: 35149129
You can use (IsNull(Field, 'False') for all those fields that you do not want them to show NULL.
0
 
LVL 33

Accepted Solution

by:
paulmacd earned 250 total points
ID: 35149136
You want the ISNULL  command:
     ISNULL ( check_expression , replacement_value )

so

     ...
     ISNULL(bit.TPM_Activated0, "False")  AS 'TPM Activated'
      ...
0
 
LVL 24

Assisted Solution

by:jimyX
jimyX earned 250 total points
ID: 35149158
So your query becomes:
SELECT     sys.AD_Site_Name0, sys.Name0, sys.User_Name0, cs.model0 AS Model, (IsNull(bit.BitLocker_Enabled0, 'False') AS 'BitLocker Enabled', (IsNull(bit.TPM_On0, 'False') AS 'TPM On', 
                      (IsNull(bit.TPM_Activated0, 'False') AS 'TPM Activated', bit.Script_Last_Run0 AS 'Last Time Script was Run'
FROM         v_GS_BitLocker_TPM_Info0 AS bit INNER JOIN
                      v_R_System AS sys ON bit.ResourceID = sys.ResourceID INNER JOIN
                      v_GS_COMPUTER_SYSTEM as cs ON sys.ResourceID = cs.ResourceID
WHERE		(sys.Operating_System_Name_and0 = 'Microsoft Windows NT Workstation 6.1') AND (cs.Model0 LIKE '%Latitude%') OR
			(sys.Operating_System_Name_and0 = 'Microsoft Windows NT Workstation 6.1') AND (cs.Model0 LIKE '%Precision M%')
ORDER BY sys.AD_Site_Name0

Open in new window

0
 
LVL 51

Expert Comment

by:HainKurt
ID: 35149170
you can use case statement like this

case
when bit.TPM_Activated0 is null then 'False'
else bit.TPM_Activated0
end
0
 

Author Closing Comment

by:Lorrec
ID: 35149380
I used a combination of both replies. Thank you very much for the quick response.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now