Monday 1 September 2008

Total Harddisk space

Thanks to Uri Dimant who posted this code in Microsoft sql server newsgroup. I am posting this in my blog just for future reference



CREATE PROCEDURE sp_totalHDDspace
AS
SET NOCOUNT ON

DECLARE @hr int
DECLARE @fso int
DECLARE @drive char(1)
DECLARE @odrive int
DECLARE @TotalSize varchar(20)
DECLARE @MB bigint ; SET @MB = 1048576

CREATE TABLE #drives (drive char(1) PRIMARY KEY,
FreeSpace int NULL,
TotalSize int NULL)

INSERT #drives(drive,FreeSpace)
EXEC master.dbo.xp_fixeddrives

EXEC @hr=sp_OACreate 'Scripting.FileSystemObject',@fso OUT
IF @hr <> 0 EXEC sp_OAGetErrorInfo @fso

DECLARE dcur CURSOR LOCAL FAST_FORWARD
FOR SELECT drive from #drives
ORDER by drive

OPEN dcur

FETCH NEXT FROM dcur INTO @drive

WHILE @@FETCH_STATUS=0
BEGIN

EXEC @hr = sp_OAMethod @fso,'GetDrive', @odrive OUT, @drive
IF @hr <> 0 EXEC sp_OAGetErrorInfo @fso

EXEC @hr = sp_OAGetProperty @odrive,'TotalSize', @TotalSize OUT
IF @hr <> 0 EXEC sp_OAGetErrorInfo @odrive

UPDATE #drives
SET TotalSize=@TotalSize/@MB
WHERE drive=@drive

FETCH NEXT FROM dcur INTO @drive

END

CLOSE dcur
DEALLOCATE dcur

EXEC @hr=sp_OADestroy @fso
IF @hr <> 0 EXEC sp_OAGetErrorInfo @fso

SELECT drive,
FreeSpace as 'Free(MB)',
TotalSize as 'Total(MB)',
CAST((FreeSpace/(TotalSize*1.0))*100.0 as int) as 'Free(%)'
FROM #drives
ORDER BY drive

DROP TABLE #drives

RETURN
go

6 comments:

Anonymous said...

Thank You for being the member of this website. Please allow me to have the possibility to express my satisfaction with Host Gator web hosting. They offer professional and quick support and they also offer numerous [url=http://tinyurl.com/gatorcoupon ]Hostgator coupon codes[/url].

I love Hostgator hosting, you will too.

http://milieu.eroding.net/index.php?action=profile;u=17041

Anonymous said...

I'm here to help get your internet site off to a great commence. Do not be one of those that wished they had accomplished it better the first time, then consider on the task, and price, of starting above. Your internet site displays what you along with your business or pastime are all about.

I am able to provide low-cost, user-friendly, custom made developed sites for any wide array of firms, organizations and teams.Additionally, it should not price a lot of money to get you started. I'll aid guide you via the procedure as well as alert you when i think you might be obtaining in more than your head, or past your spending budget.

Here are some hight top quality services to get a resonable cost:

Front-End Development
Custom web site design
Affordable web site design
E-Commerce website design
Corporate Website Design
Innovative website design
Static Web Design
Website maintenance
Web site re-designs
SEO Services
Logo Design

Please look around the site for further information about the [url=http://www.adrianbotea.com]freelance web designer[/url] services that I am able to offer and to see examples of websites that I have designed

--------------------------------

[url=http://www.adrianbotea.com/seo-services][img]http://www.adrianbotea.com/seo-moz.png[/img][/url]

Anonymous said...

yGhh michael kors handbags outlet
mBez styler ghd
yLli north face store
9qMwx cheap uggs
4sJqb michael kors bags

Anonymous said...

4rBuo ghd hair straighteners
rDnx ugg boots sale
uAgi michael kors purses
4gShw GHD
7mFtw burberry bags
1wUew bottes ugg
9oLzd ghd nz
2eTaf louis vuitton sale
0gNfx michael kors outlet
9yVaw cheapest ghd
8zZlw cheap uggs
7fUru cheap nfl jerseys
6uVlg michael kors bags
6kBxc GHD Pas Cher
4sXmc ugg boots

Anonymous said...

The information were very helpful for me, I've bookmarked this post, Please share more information about this
Thanks

Anonymous said...

Hello. And Bye.