I created a stored procedure that will return the error code if it fails. When executing the proc, I get the message like this and what is returned is
Output Messages:
Server: Msg 242, Level 16, State 3, Procedure p_load_data, Line 280
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
Under Grids :
-6
Code :
SET NOCOUNT ON
DECLARE @RET_VAL int
EXEC @RET_VAL = p_load_data
SELECT @RET_VAL
Procedure:
CREATE PROCEDURE p_load_data
AS
DECLARE @error_var int
, @Record_Id char(1)
, @Emp_ID varchar (9)
, @FName varchar (50)
, @MName varchar (50)
, @LName varchar (50)
, @BirthDt datetime
DECLARE Stage_Cursor CURSOR
FOR
SELECT Record_Id,Emp_ID,FName,MName,LName,BirthDt
FROM Stage_Table
OPEN Stage_Cursor
FETCH NEXT FROM Stage_Cursor
INTO
@Record_Id,@Emp_ID,@FName,@MName,@LName,@BirthDt
WHILE @@FETCH_STATUS = 0
BEGIN
IF RTRIM(LTRIM(@BirthDt)) = ''
SET @BirthDt = NULL
INSERT INTO Table2(Record_Id,Emp_ID,FName,MName,LName,BirthDt)
VALUES(@Record_Id,@Emp_ID,@FName,@MName,@LName,@BirthDt)
SELECT @error_var = @@ERROR
IF @error_var <> 0
RETURN(@error_var)
END
FETCH NEXT FROM Stage_Cursor
INTO @Record_Id,@Emp_ID,@FName,@MName,@LName,@BirthDt
END
CLOSE Stage_Cursor
DEALLOCATE Stage_Cursor
Output Messages:
Server: Msg 242, Level 16, State 3, Procedure p_load_data, Line 280
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
Under Grids :
-6
Code :
SET NOCOUNT ON
DECLARE @RET_VAL int
EXEC @RET_VAL = p_load_data
SELECT @RET_VAL
Procedure:
CREATE PROCEDURE p_load_data
AS
DECLARE @error_var int
, @Record_Id char(1)
, @Emp_ID varchar (9)
, @FName varchar (50)
, @MName varchar (50)
, @LName varchar (50)
, @BirthDt datetime
DECLARE Stage_Cursor CURSOR
FOR
SELECT Record_Id,Emp_ID,FName,MName,LName,BirthDt
FROM Stage_Table
OPEN Stage_Cursor
FETCH NEXT FROM Stage_Cursor
INTO
@Record_Id,@Emp_ID,@FName,@MName,@LName,@BirthDt
WHILE @@FETCH_STATUS = 0
BEGIN
IF RTRIM(LTRIM(@BirthDt)) = ''
SET @BirthDt = NULL
INSERT INTO Table2(Record_Id,Emp_ID,FName,MName,LName,BirthDt)
VALUES(@Record_Id,@Emp_ID,@FName,@MName,@LName,@BirthDt)
SELECT @error_var = @@ERROR
IF @error_var <> 0
RETURN(@error_var)
END
FETCH NEXT FROM Stage_Cursor
INTO @Record_Id,@Emp_ID,@FName,@MName,@LName,@BirthDt
END
CLOSE Stage_Cursor
DEALLOCATE Stage_Cursor