您好我正在研究sql存储过程。目前,检查服务器上的磁盘空间量,然后在一定量(100MB)下向用户发送电子邮件通知。我只是想对下面的一些代码做一些澄清:
SET @tableHTML = 'This is to notify you that Insufficient disk space encountered
in' + @DiskDrive + ' Drive' + '('+ + ')' + 'in SQLCircuit
我只是在找人解释'('''''''的作用。完整代码如下:
CREATE PROCEDURE [dbo].[GetServerSpaceStatus]
AS
BEGIN
SET NOCOUNT ON
DECLARE @sErrorMessage AS NVARCHAR(255)
DECLARE @lErrorMessageID AS INT
DECLARE @lReturnCode AS INT
DECLARE @sMessage AS NVARCHAR(4000)
DECLARE @lIdentity AS INT
DECLARE @DiskDrive AS NVARCHAR(100)
DECLARE @DiskSpace AS INT
DECLARE @SUBJECTMESSAGE NVARCHAR(500)
DECLARE @tableHTML NVARCHAR(500)
BEGIN TRY
--Declaring table variable for storing Disk space information
DECLARE @DiskFreeSpace AS TABLE
(
Drive CHAR(1),
MB_Free INT
)
--Inserting disk space availability details into table variable
INSERT INTO @DiskFreeSpace
EXEC xp_fixeddrives
--Storing drive name and free space(in MB) in variable.
--Creteria for insufficient disk space equal or less than 100 MB
SELECT @DiskDrive= Drive ,
@DiskSpace = MB_Free
FROM @DiskFreeSpace
WHERE MB_Free < 100
SET @SUBJECTMESSAGE= 'Production Support Mail: Insufficent Disk Space in ' +
@DiskDrive + ' Drive in SQLCircuit Blogspot Server'
SET @tableHTML = 'This is to notify you that Insufficient disk space encountered
in' + @DiskDrive + ' Drive' + '('+ + ')' + 'in SQLCircuit
Blogspot Server, Please take necessary action to avoid any further issues' +
CHAR(4) + 'Thanks,' + CHAR(4) +'SQLCircuit Team'
--Sending Mail
EXEC msdb.dbo.sp_send_dbmail
@recipients='sqlcircuit@gmail.com',
@subject = @SUBJECTMESSAGE,
@Profile_Name='sqlcircuit', --Profile of SMTP Server
@body = @tableHTML,
@body_format = 'HTML' ;
SET @lReturnCode = 0
END TRY
BEGIN CATCH
--logging Error information
INSERT INTO [dbo].[ErrorLog]
([MessageID],[ErrorNumber],[ErrorSeverity],[ErrorState],
[ErrorProcedure],[ErrorLine],[ErrorMessage],[CreatedBy],
[CreatedDate])
VALUES
(1,ERROR_NUMBER(),ERROR_SEVERITY(),ERROR_STATE(),ISNULL(ERROR_PROCEDURE(), '-
'),ERROR_LINE(),ERROR_MESSAGE(),'',GETDATE())
END CATCH
RETURN @lReturnCode
SET NOCOUNT OFF
END
答案 0 :(得分:0)
我愿意打赌这是一个错字。也许原作者打算在那时将变量的内容插入到消息中,而忘记这样做。
SQL Server将第一个+
解释为字符串连接运算符,将第二个+
解释为后面的字符串上的unary plus。该运算符仅适用于数字操作数,但在此上下文中仍允许使用它。微软在TechNet上发表声明here,他们声称这是一个错误,但是一个好的错误,并且由于向后兼容性问题,他们并不打算修复它。