SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 T-SQL Query Help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

dimepop
Starting Member

30 Posts

Posted - 07/12/2012 :  08:18:01  Show Profile  Reply with Quote
Hi,
Can i get some help with a query?
Having the below database
Which query will give me the % of Computers in Computername grouped by the first 4 letters (where they give me the site location) and where TimetoLogon over 60 and WindowsVersion Any of the XP versions?( SP1, SP2, SP3)

ComputerName TimeToLogon WindowsVersion
----------- ------------ ----------------
sfc1-080 43 Microsoft Windows XP Professional Service Pack 3
nyc1-188 12 Microsoft Windows 7 Enterprise Service Pack 1
lan1-323 16 Microsoft Windows XP Professional Service Pack 3
lan2-190 11 Microsoft Windows 7 Enterprise Service Pack 1
lan3-190 16 Microsoft Windows XP Professional Service Pack 3
hou1-559 98 Microsoft Windows XP Professional Service Pack 3
sea1-020 38 Microsoft Windows XP Professional Service Pack 3

I have this query that gets the % of Computers starting by lan with timetologon over 60 by now i would like to include all sites and include only the XP versions.


"SELECT LEFT (ComputerName, CHARINDEX('-', ComputerName) - 1) AS Expr1, COUNT(CASE WHEN TimeToLogon > 60 THEN 1 END) * 100.0 / NULLIF (COUNT(1), 0) AS [%Over60] FROM BootLog WHERE (ComputerName LIKE 'lan%') GROUP BY LEFT (ComputerName, CHARINDEX('-', ComputerName) - 1)"


So at the end i will end up with a result like for windows XP machines:
Site %Timetologonover60
sfc1 12
lan1 11
lan2 12
hou1 12

Thanks

dimepop
Starting Member

30 Posts

Posted - 07/12/2012 :  08:21:10  Show Profile  Reply with Quote
I forgot to include something....
There is another row called DateAndTime with values like:
2012-03-14 09:37:12.000
2012-03-14 08:37:59.000
2012-03-14 08:38:30.000
2012-03-14 08:39:41.000
2012-03-14 08:39:56.000
2012-03-14 08:40:34.000
2012-03-14 08:41:25.000

the report ideally will only look at the last 30 days.

Thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47173 Posts

Posted - 07/12/2012 :  09:53:09  Show Profile  Reply with Quote

SELECT LEFT (ComputerName, CHARINDEX('-', ComputerName) - 1) AS Expr1,
 COUNT(CASE WHEN TimeToLogon > 60 THEN 1 END) * 100.0 / NULLIF (COUNT(1), 0) AS [%Over60] 
FROM BootLog 
WHERE  WindowsVersion LIKE 'Windows XP%'
and DateAndTime >= DATEADD(DD,dATEDIFF(dd,0,GETDATE())-30,0)
GROUP BY LEFT (ComputerName, CHARINDEX('-', ComputerName) - 1)


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

dimepop
Starting Member

30 Posts

Posted - 07/12/2012 :  11:46:41  Show Profile  Reply with Quote
Hi Visakh, thanks for the query.
It runs perfectly.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47173 Posts

Posted - 07/12/2012 :  17:24:41  Show Profile  Reply with Quote
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

dimepop
Starting Member

30 Posts

Posted - 07/13/2012 :  07:57:58  Show Profile  Reply with Quote
Hi Visakh16
Which query would display the following?
I would like to add the second row so i can display both in a combochart
Thanks

Site %XPTimetoLogonOver60 %Win7TimetoLogonOver60
sfc1 12 22
lan1 11 21
lan2 12 22
hou1 12 22

Edited by - dimepop on 07/13/2012 08:12:05
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47173 Posts

Posted - 07/13/2012 :  10:35:34  Show Profile  Reply with Quote

SELECT LEFT (ComputerName, CHARINDEX('-', ComputerName) - 1) AS Expr1,
 COUNT(CASE WHEN TimeToLogon > 60 AND WindowsVersion LIKE 'Windows XP%' THEN 1 END) * 100.0 / NULLIF (COUNT(1), 0) AS [%XPOver60],
 COUNT(CASE WHEN TimeToLogon > 60 AND WindowsVersion LIKE 'Windows 7%' THEN 1 END) * 100.0 / NULLIF (COUNT(1), 0) AS [%Win7Over60]  
FROM BootLog 
WHERE  (WindowsVersion LIKE 'Windows XP%' OR  WindowsVersion LIKE 'Windows 7%')
and DateAndTime >= DATEADD(DD,dATEDIFF(dd,0,GETDATE())-30,0)
GROUP BY LEFT (ComputerName, CHARINDEX('-', ComputerName) - 1)


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

dimepop
Starting Member

30 Posts

Posted - 07/13/2012 :  11:41:51  Show Profile  Reply with Quote
Thanks, I Owe you a drink!
:)
Go to Top of Page

dimepop
Starting Member

30 Posts

Posted - 07/16/2012 :  07:33:09  Show Profile  Reply with Quote
Hi Visakh, sorry to bother you again, it seems that the last query doesn't work as expected.
The query returns the correct % of Win7 machines, but the incorrect % of XP machines.
If i run the query just to get the % of xp machines i get a different result as in the combined query.
Can you help?
Many thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47173 Posts

Posted - 07/16/2012 :  10:00:23  Show Profile  Reply with Quote
explain with sample data what issue you're facing. I cant make out exact issue without seeing sample output.

my only guess now is probably you're after this??


SELECT LEFT (ComputerName, CHARINDEX('-', ComputerName) - 1) AS Expr1,
 COUNT(CASE WHEN TimeToLogon > 60 AND WindowsVersion LIKE 'Windows XP%' THEN 1 END) * 100.0 / NULLIF (COUNT(CASE WHEN WindowsVersion LIKE 'Windows XP%' THEN 1 END), 0) AS [%XPOver60],
 COUNT(CASE WHEN TimeToLogon > 60 AND WindowsVersion LIKE 'Windows 7%' THEN 1 END) * 100.0 / NULLIF (COUNT(CASE WHEN WindowsVersion LIKE 'Windows 7%' THEN 1 END), 0) AS [%Win7Over60]  
FROM BootLog 
WHERE  (WindowsVersion LIKE 'Windows XP%' OR  WindowsVersion LIKE 'Windows 7%')
and DateAndTime >= DATEADD(DD,dATEDIFF(dd,0,GETDATE())-30,0)
GROUP BY LEFT (ComputerName, CHARINDEX('-', ComputerName) - 1)


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

dimepop
Starting Member

30 Posts

Posted - 07/16/2012 :  11:03:58  Show Profile  Reply with Quote
Hi Visakh, now it works fine, but before the results for XP were wrong.
I noticed it because if i run the query to get the results for just XP then it gave me different results.
No the combines query shows the same results as the individual queries.
Many Thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47173 Posts

Posted - 07/16/2012 :  11:42:51  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000