| Author |
Topic |
|
dimepop
Starting Member
33 Posts |
Posted - 2012-07-06 : 09:26:33
|
| Hi i have a query that returns this result..QUERY:SELECT Computername, TimeToLogon FROM dbo.boottimeComputerName TimeToLogonDesktop-152 129Desktop-038 120Desktop-366 84Desktop-054 132Desktop-053 150Desktop-433 0Laptop-043 189Laptop-017 69Laptop-357 165Laptop-133 170Laptop-153 60It has of course many more records that these..I would like to get the percentage of Desktops which TimetoLogon is Over 60How can i achieve this?Thanks |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2012-07-06 : 09:29:56
|
| select100.0 * (select count(*) from boottime where ComputerName like 'Desktop%' and TimeToLogon > 60)/(select count(*) from boottime where ComputerName like 'Desktop%')==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-07-06 : 09:32:08
|
| [code]SELECT LEFT(ComputerName,CHARINDEX('-',ComputerName)-1),COUNT(CASE WHEN TimeToLogon > 60 THEN 1 END) * 100.0/COUNT(1) AS [%Over60]FROM dbo.boottimeWHERE ComputerName LIKE 'Desktop%'GROUP BY LEFT(ComputerName,CHARINDEX('-',ComputerName)-1)[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
dimepop
Starting Member
33 Posts |
Posted - 2012-07-06 : 09:49:32
|
| Hi guys good effort but it doesn't seem to work.Both queries execute successfully but they don't return any values.. ??Thanks |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-07-06 : 09:51:56
|
quote: Originally posted by dimepop Hi guys good effort but it doesn't seem to work.Both queries execute successfully but they don't return any values.. ??Thanks
Then I'm sure you've some other part which you've not told us so far. Are you sure the values exist exactly like what you've shown in previos post?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
dimepop
Starting Member
33 Posts |
Posted - 2012-07-06 : 09:52:35
|
Hi, actually this query returned with errors:Msg 8134, Level 16, State 1, Line 1Divide by zero error encountered.quote: Originally posted by nigelrivett select100.0 * (select count(*) from boottime where ComputerName like 'Desktop%' and TimeToLogon > 60)/(select count(*) from boottime where ComputerName like 'Desktop%')==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy.
|
 |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2012-07-06 : 09:53:18
|
| Provide a little more info. Follow the link in my sig, it will tell you how to provide said info.How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-07-06 : 10:00:34
|
| [code]SELECT LEFT(ComputerName,CHARINDEX('-',ComputerName)-1),COUNT(CASE WHEN TimeToLogon > 60 THEN 1 END) * 100.0/NULLIF(COUNT(1),0) AS [%Over60]FROM dbo.boottimeWHERE ComputerName LIKE 'Desktop%'GROUP BY LEFT(ComputerName,CHARINDEX('-',ComputerName)-1)[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
dimepop
Starting Member
33 Posts |
Posted - 2012-07-06 : 10:11:31
|
| Hi, i am now running them and they seem to work, with both queries showing the same results.Before visakh16 was showing a different result.Thanks a lot for the help, this community is great.Can you guys suggest some tutorials to learn how to make my own queries?There is some many stuff around the web that i just get lost.Many Thanks |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-07-06 : 10:33:52
|
quote: Originally posted by dimepop Hi, i am now running them and they seem to work, with both queries showing the same results.Before visakh16 was showing a different result.Thanks a lot for the help, this community is great.Can you guys suggest some tutorials to learn how to make my own queries?There is some many stuff around the web that i just get lost.Many Thanks
start with below to learn basicshttp://www.w3schools.com/sql/default.asp------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|