Ejemplo de ELSE y ELSE IF en SQL Server
SQL Server
- Por Programador ASP clásico /
- 07/03/2013 @ 08:44:38 /
- 1006 visitas
Este es un ejemplo de else y else if aplicado en Transact SQL Server
-- Replace the default error message and numbers with my own:
CREATE PROCEDURE spRunSQL
@Statement VarChar(2000) -- Input param. accepts any SQL statement.
AS
DECLARE @StartTime DateTime
, @EndTime DateTime
, @ExecutionTime Int
, @ErrNum Int
SET @StartTime = GetDate()
EXECUTE (@Statement)
SET @ErrNum = @@Error
IF @ErrNum = 207 -- Bad column
RAISERROR 50001 'Bad column name'
ELSE IF @ErrNum = 208 -- Bad object
RAISERROR 50002 'Bad object name'
ELSE IF @ErrNum = 0 -- No error. Resume.
BEGIN
SET @EndTime = GetDate()
SET @ExecutionTime = DateDiff(MilliSecond, @StartTime, @EndTime)
RETURN @ExecutionTime -- Return execution time in milliseconds
END
GO
tags: