Solved

Modify output results of SQL 2005 query

Posted on 2011-03-16
5
321 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 34

Accepted Solution

by:
Paul MacDonald 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 52

Expert Comment

by:Huseyin KAHRAMAN
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

726 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