Create PROCEDURE sp_hexadecimal @binvalue varbinary(255), @hexvalue varchar(255) OUTPUT AS DECLARE @charvalue varchar(255) DECLARE @i int DECLARE @length int DECLARE @hexstring char(16) SELECT @charvalue = '0x' SELECT @i = 1 SELECT @length = DATALENGTH(@binvalue) SELECT @hexstring = '0123456789abcdef' WHILE (@i <= @length) BEGIN DECLARE @tempint int DECLARE @firstint int DECLARE @secondint int SELECT @tempint = CONVERT(int, SUBSTRING(@binvalue,@i,1)) SELECT @firstint = FLOOR(@tempint/16) SELECT @secondint = @tempint - (@firstint*16) SELECT @charvalue = @charvalue + SUBSTRING(@hexstring, @firstint+1, 1) + SUBSTRING(@hexstring, @secondint+1, 1) SELECT @i = @i + 1 END SELECT @hexvalue = @charvalue
GO
Create PROCEDURE sp_displayoaerrorinfo @object int, @hresult int AS DECLARE @output varchar(255) DECLARE @hrhex char(10) DECLARE @hr int DECLARE @source varchar(255) DECLARE @description varchar(255) PRINT 'OLE Automation Error Information' EXEC sp_hexadecimal @hresult, @hrhex OUT SELECT @output = ' HRESULT: ' + @hrhex PRINT @output EXEC @hr = sp_OAGetErrorInfo @object, @source OUT, @description OUT IF @hr = 0 BEGIN SELECT @output = ' Source: ' + @source PRINT @output SELECT @output = ' Description: ' + @description PRINT @output END ELSE BEGIN PRINT 'sp_OAGetErrorInfo failed.' RETURN END
GO
create proc usp_Test As BEGIN DECLARE @hr integer DECLARE @obj integer DECLARE @results bit
EXEC @hr = sp_OACreate 'CDO.Message', @obj OUTPUT
IF @hr <> 0 BEGIN EXEC sp_displayoaerrorinfo @obj,@hr END Else Print 'CDO Lib is installed on your system'
EXEC @hr = sp_OADestroy @obj IF @hr <> 0 BEGIN EXEC sp_displayoaerrorinfo @obj,@hr END END GO
Exec usp_Test |