| Author |
Topic |
|
superleeds
Starting Member
9 Posts |
Posted - 2008-01-11 : 08:25:24
|
| Hi All,Running SQL 2005DB as a colum that contains hundreds of file types ie, mp3,wav,txt,doc,pdf, etc When i run the folowinguse DB go select file1from dbo.DBwhere file1 like '%'I get back (4192103 row(s) affected)What would run to get back how many mp3's,docs'txt files there are?Kind RegardsLeeds |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-01-11 : 08:29:34
|
Do you have file type as a column in the table?Select FileType, count(*)from Tablegroup by FileType Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-01-11 : 09:15:27
|
| Also note that where file1 like '%' would return all rows. If you want to find the file that has %, then use where file1 like '[%]'MadhivananFailing to plan is Planning to fail |
 |
|
|
superleeds
Starting Member
9 Posts |
Posted - 2008-01-14 : 06:35:48
|
| Thanks for that, but is there a way I can get an amount of each filesay likemp3 2345doc 345txt 456456ini 34 |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-01-14 : 06:45:08
|
Harsh told you how, three days ago.-- Prepare sample dataDECLARE @Sample TABLE (FileName VARCHAR(257))INSERT @SampleSELECT 'c:\peso\ago.gif' UNION ALLSELECT 'd:\windows\system\start.gif' UNION ALLSELECT 'http://www.developerworkshop.net/babyDBA.jpg' UNION ALLSELECT 'test'-- Show the expected outputSELECT Extension, COUNT(*) AS ItemsFROM ( SELECT CASE WHEN FileName LIKE '%.%' THEN RIGHT(FileName, CHARINDEX('.', REVERSE(FileName)) - 1) ELSE 'No filetype/extension' END AS Extension FROM @Sample ) AS dGROUP BY ExtensionORDER BY Extension E 12°55'05.25"N 56°04'39.16" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-01-14 : 06:46:50
|
quote: Originally posted by superleeds Thanks for that, but is there a way I can get an amount of each filesay likemp3 2345doc 345txt 456456ini 34
by amount, did you mean count or file size?MadhivananFailing to plan is Planning to fail |
 |
|
|
superleeds
Starting Member
9 Posts |
Posted - 2008-01-14 : 07:49:31
|
| It was the actual Count i was looking for, I have tried all the above but it doesn't work :(Cheers |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-01-14 : 08:00:19
|
Not even the one suggested to you 01/14/2008 : 06:45:08 ? E 12°55'05.25"N 56°04'39.16" |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-01-14 : 08:09:50
|
| Then probably you should give us Table structures, sample data with your question. Incomplete information is going to end up giving incomplete/wrong solutions.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-01-14 : 08:10:13
|
quote: Originally posted by superleeds It was the actual Count i was looking for, I have tried all the above but it doesn't work :(Cheers
What do you mean by "it doesn't work"?Did you get any error?MadhivananFailing to plan is Planning to fail |
 |
|
|
superleeds
Starting Member
9 Posts |
Posted - 2008-01-14 : 08:16:04
|
| Afraid not :(the one that harsh suggested did work, but it gives me back the amount of files on each PC in the organization, over 3000 machines, I just want an overall count of each of the files in the org.Thanks for the help on this, very much appreciated indeed |
 |
|
|
superleeds
Starting Member
9 Posts |
Posted - 2008-01-16 : 07:06:03
|
| Hope this helps a bit more with my issueTrying to get this resultHostname username file1 discovereddevice displaynamethe tables areTable 1 UniqueID hostname username 382119a3-215e-6 orbiter223 mellytTable2 File1 time discovereddeviceMp3 09/11/2007 16:40:54 HP DATASTOREDoctxttable3deviceclass deviceflags displayname4df45rse456fg 20361645 HP |
 |
|
|
superleeds
Starting Member
9 Posts |
Posted - 2008-01-17 : 09:03:13
|
| Any Ideas please? |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-01-17 : 09:29:09
|
SELECT File1, COUNT(*) AS FilesFROM Table2 GROUP BY File1ORDER BY COUNT(*) DESC E 12°55'05.25"N 56°04'39.16" |
 |
|
|
superleeds
Starting Member
9 Posts |
Posted - 2008-01-17 : 09:49:12
|
| Thank you Peso.worked a treat. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-01-17 : 10:06:39
|
You are welcome.But Harsh told you exactly the same thing 01/11/2008 : 08:29:34 ! E 12°55'05.25"N 56°04'39.16" |
 |
|
|
superleeds
Starting Member
9 Posts |
Posted - 2008-01-17 : 10:26:17
|
| Sorry Harsh, i must have done a typo that day, so thank you kindly, the both of you that is.would i be asking to much if you ciould tell me the followingTrying to get this resultHostname username file1 discovereddevice displaynamethe tables areTable 1 UniqueID hostname username 382119a3-215e-6 orbiter223 mellytTable2 File1 time discovereddeviceMp3 09/11/2007 16:40:54 HP DATASTOREDoctxttable3deviceclass deviceflags displayname4df45rse456fg 20361645 HP |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-01-17 : 10:29:28
|
Use INNER JOIN in your query. E 12°55'05.25"N 56°04'39.16" |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-01-17 : 10:29:37
|
| What is the common column in these three tables? how they are related?Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-01-17 : 10:30:44
|
| dont you have linking column among these tables? |
 |
|
|
superleeds
Starting Member
9 Posts |
Posted - 2008-01-17 : 11:10:42
|
| Harsh, Im new to SQL You would have never guessed would ya :)the common column is hostname |
 |
|
|
Next Page
|