views:

137

answers:

2

I need my query to pull all DirName's what have the following prefix 'site/test/test/' is the correct syntax a '*'

SELECT  DirName, count(*) AS FileCount, SUM(Size)/1024 as 'SizeKB' 
FROM  alldocs
Where DirName = 'site/test/test/*'
GROUP BY  dirName 
ORDER BY DirName
+5  A: 

You need to use SQL's LIKE clause:

SELECT  DirName, count(*) AS FileCount, SUM(Size)/1024 as 'SizeKB' 
FROM  alldocs
Where DirName LIKE 'site/test/test/%'
GROUP BY  dirName 
ORDER BY DirName

See http://www.sql-tutorial.net/SQL-LIKE.asp

karim79
Perfect! Thanks
MG
Is there an easy was to include a column total for 'SizeKB'?
MG
@MG - better if you ask that in another question, to avoid an off-topic discussion using comment space.
karim79
A: 

Are you using MySQL? If you are, you can use LEFT in something like

SELECT  DirName, count(*) AS FileCount, SUM(Size)/1024 as 'SizeKB' 
FROM  alldocs
Where LEFT( DirName, LENGTH( 'site/test/test/' ) ) = 'site/test/test/'
GROUP BY  dirName 
ORDER BY DirName
bobobobo
MS sql server doesn't recognize the Length funtion.
MG