Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 How to check file size in bytes

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2015-02-02 : 17:30:25
I have the sp, with the below script within it. when fileexists, sometimes the filesize is toomuch due to that the job failing. to email. saying file size exceeded.

is it possible to check the filesize:



EXEC Master.dbo.xp_fileexist @filepath,@File_Exists OUT
IF @File_Exists = 1
BEGIN
DELETE Tab_EmailDistribution WHERE emailid=@emailid

EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'fROM_DB_Mail1',
@recipients=@recipient,
@copy_recipients = @copymailto,
@body = @mailbody,
@subject=@Subject,
@file_attachments=@filepath
END



Thanks a lot for the helpful info.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2015-02-02 : 17:39:05
Why don't you change the Database Mail properties so that it can send a larger file size? But if you want to check the file size via T-SQL, I think the only way to do it is through xp_cmdshell, which is not recommended. Instead, I would recommend a PoSH script.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2015-02-03 : 01:49:45
Hi, if you want to use Powershell - use commands in this script to check file size.
http://www.sqlserver-dba.com/2012/06/powershell-script-to-compare-two-file-sizes.html
If you wanted you could set thresholds.


Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page
   

- Advertisement -