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
 General SQL Server Forums
 New to SQL Server Programming
 How to check record are inserted in IF condition.

Author  Topic 

hspatil31
Posting Yak Master

182 Posts

Posted - 2011-11-17 : 06:49:33
Dear All,

I am having following query in store procedure, through this query I am inserting more that 3 Lakh records at a time in EMPLOYEE table from the EMPLOYEE_T table.

Now I want to check If insertion is successful then TRUNCATE the EMPLOYEE_T table with If condition.

Can anybody please tell me how to do this ?

Query:
BEGIN TRANSACTION;

INSERT INTO EMPLOYEE (EMPID,EMPNAME,MARKS)
SELECT EMPID,EMPNAME,MARKS FROM EMPLOYEE_T

COMMIT TRANSACTION;

Thanks and Regard's
Harish Patil

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-11-17 : 07:48:01
See Try/Catch for example
http://msdn.microsoft.com/de-de/library/ms175976.aspx


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

hspatil31
Posting Yak Master

182 Posts

Posted - 2011-11-17 : 08:05:49
Hello Friend,

Can I do as following, Is this correct way or not ?

BEGIN TRANSACTION;

INSERT INTO EMPLOYEE (EMPID,EMPNAME,MARKS)
SELECT EMPID,EMPNAME,MARKS FROM EMPLOYEE_T

COMMIT TRANSACTION;

IF @@ROWCOUNT != 0
BEGIN
TRUNCATE TABLE EMPLOYEE_T
END
ELSE
BEGIN
ROLLBACK TRANSACTION;
END


Thanks and Regard's
Harish Patil
Go to Top of Page
   

- Advertisement -