Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Unable to see the available space value in @alertMessage


Unable to see the available space value in @alertMessage

Author
Message
sqlnewbee 46327
sqlnewbee 46327
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 38
Hi Guru's,

I am new to this forum and having below issue.

The below code is working fine but the problem is I am not able to see the available space value in @alertMessage through email.
could you please help me?

DECLARE @list nvarchar(2000) = '';
WITH core AS (
SELECT DISTINCT
s.volume_mount_point [Drive],
CAST(s.available_bytes / 1048576 as decimal(12,2)) [AvailableMBs],
((CAST(s.total_bytes / 1048576.0 as decimal(20,2)))*97)/100 FifteenpercentAvailableMBs

FROM
sys.master_files f
CROSS APPLY sys.dm_os_volume_stats(f.database_id, f.[file_id]) s
)

SELECT @list = @list + ' ' + Drive

FROM core
WHERE AvailableMBs < FifteenpercentAvailableMBs

DECLARE @alertMessage varchar(500)
DECLARE @subject varchar(100)
DECLARE @AvailableMBs int


IF LEN(@list) > 3

BEGIN
SET @alertMessage ='Low Disk Space Notification. The following drives are currently reporting Lessthan15percentAvailableMBs,'+@list
SET @Subject = 'Drive free space is low on server - ' + @@SERVERNAME


EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'SQL Server Profile',
@recipients ='xxx@gmail.com',
@body =@alertMessage,
@importance = 'High',
@subject = @Subject;

END

--EXEC xp_fixeddrives

Thanks,
SQLNewBee
sqlnewbee 46327
sqlnewbee 46327
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 38
Hello Guru's,

no reply from any one. If you have any idea or solution please post.

Thanks,
Sean Pearce
Sean Pearce
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1170 Visits: 3432
The maths is not correct. Try this in your CTE.

WITH core AS (
SELECT DISTINCT
s.volume_mount_point [Drive],
s.available_bytes / 1024 / 1024 [AvailableMBs],
s.total_bytes / 1024 / 1024 [TotalMBs],
(s.available_bytes / 1024. / 1024) / (s.total_bytes / 1024. / 1024) * 100 AS AvailablePercent
FROM
sys.master_files f
CROSS APPLY
sys.dm_os_volume_stats(f.database_id, f.[file_id]) s
WHERE
(s.available_bytes / 1024. / 1024) / (s.total_bytes / 1024. / 1024) * 100 < 15)
SELECT @list = @list + ' ' + Drive
FROM core;





The SQL Guy @ blogspot

@SeanPearceSQL

About Me
sqlnewbee 46327
sqlnewbee 46327
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 38
Hi Sean Pearce,

Thank you so much for your help. Now I am getting message that the command successful but no email. Earlier I use to get the email.

Thank you once again,
SQLNewBee
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search