Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Handling

Status
Not open for further replies.

desireemm

Technical User
Dec 17, 2003
50
US
I am getting an error message with the error handling I just added to this stored procedure anyone know why

Code:
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

ALTER  PROCEDURE dbo.[SURVEILLANCE-VBM]
AS INSERT INTO dbo.GCEmployeeTerms
                      ([TM #], FirstName, LastName, SocialSecurityNumber, TerminationDate, Title, DepartmentName)
SELECT     [TM #], FirstName, LastName, SocialSecurityNumber, TerminationDate, Title, DepartmentName
FROM         dbo.Termination_View
WHERE     (DepartmentName = N'SURVEILLANCE - VBM')
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
IF @@ERROR <> '0'
GO

[\code]

this is the error message I am getting 

Server: Msg 170, Level 15, State 1, Line 2
Line 2: Incorrect syntax near '0'.
 
If have an If without a 'then' part. If @@Error <> '0' what is supposed to happen?

IF @@ERROR <> '0'

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
So, if I understand correctly, if altering the stored procedure errors, then you want the query to return an error.

If you are altering the stored procedure in QA, then you can just remove the If @@Error <> '0' line and let QA show you the errors.



-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
I was trying to add Error Handling to the already exsisting stored procedure
 
Your stored proecedure only executes one SQL String within it. Unless you want to trap a specific error and alter the returned error message, then you don't really need error handling in the stored procedure.

If an error occurs within your SP, it will be returned to the client that called it (C++, VB, ASP, etc...).


@@Error returns an integer, so you shouldn't use quotes around it. For example...

If @@Error <> 0
Begin
Print 'An error occurred'
End



-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Code:
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

ALTER  PROCEDURE dbo.[SURVEILLANCE-VBM]
AS INSERT INTO dbo.GCEmployeeTerms
                      ([TM #], FirstName, LastName, SocialSecurityNumber, TerminationDate, Title, DepartmentName)
SELECT     [TM #], FirstName, LastName, SocialSecurityNumber, TerminationDate, Title, DepartmentName
FROM         dbo.Termination_View
WHERE     (DepartmentName = N'SURVEILLANCE - VBM')

[b]IF @@ERROR <> 0
    Begin

    Print 'An Error Occurred'

    End[/b]
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 

GO

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
I'm just trying to add error handling to my stored procedures, thats all. Allot of my stored procedures dont have Error handling
 
thank you George, your awesome that helped allot

I appreciate it :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top