Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Error handling

Author  Topic 

ddtopgun
Starting Member

26 Posts

Posted - 2014-07-23 : 03:11:47
i want to ask about error handling..

i have the statement insert in the sp


IF @StatementType ='Insert'
BEGIN
-- DECLARE
-- @vCount int


SET NOCOUNT ON;
--SET @exists='DATA SUDAH ADA';
--SELECT @vCount=COUNT(*) FROM Departemen WHERE idDepartemen=@idDepartemen
--IF @vCount=0
IF EXISTS (SELECT * FROM Departemen)
BEGIN
--for error handling with parameter
END
ELSE
BEGIN
INSERT INTO [dbo].[Departemen](nmDepartemen) VALUES (UPPER(@nmDepartemen))
END

--ELSE
-- RAISERROR('DATA SUDAH ADA',5,1)

--SELECT nmDepartemen FROM Departemen
END


i want to insert data but if the data is exists so the sp send the error to my program with parameter..

or if have the best other way for the code
plz tell me..

anyone can help me..

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-07-23 : 11:02:24
Give your sp an OUTPUT parameter and set it for both the error and success branches. Make the application expect the output parameter and look at the results upon completion of the sp.
Go to Top of Page
   

- Advertisement -