Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

sql server stored procedure logic problem Expand / Collapse
Author
Message
Posted Thursday, March 7, 2013 2:02 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Yesterday @ 10:16 PM
Points: 209, Visits: 4,503
HI friends i have small doubt in sql server.plese tell me how to solve this issuse


i have 2 tables based on that i want load first table records into second table useing stored procedure. structure is same in both table
columns like id ,name,sal in both table same columns.



first table contains 1000 records .
when ever we insert this records into second table that time 501 record is failed.
when ever we load records what ever failed record that records must be showing errore message and remaing reords must be to load .
that means when ever we applaying try catach method in stored procedure to handle errore .first in try methode to appply logic
and catch metode is devlop errore message(501 records) once its catach errore.that errore is showing that records and remaing records(502 to 1000 records) to loaded in to
second table


plese tell me how to implement logic code in try catch block.
Post #1427836
Posted Thursday, March 7, 2013 2:13 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, June 20, 2013 7:32 AM
Points: 31, Visits: 50
Hi!

You can capture all raised errors in a table type variable.
		BEGIN TRY
EXEC(@SQL)
END TRY
BEGIN CATCH
UPDATE @tFirmen SET ErrorMSG = ERROR_MESSAGE()
WHERE ID = @FirmaID
END CATCH

After execution you can handle the errors or even re-raise the original exception.
Post #1427843
Posted Thursday, March 7, 2013 2:32 AM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Friday, July 18, 2014 2:39 AM
Points: 406, Visits: 772
You should find out what is causing the error and handle it in the script rather than adding try catch for this purpose. Error may be from datatype mismatch or because of constraints. Check it and handle it in the script.
Post #1427849
Posted Thursday, March 7, 2013 8:03 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 1:14 PM
Points: 13,139, Visits: 11,980
Please stop cross posting your questions. It only fragments replies.

Direct future responses here. http://www.sqlservercentral.com/Forums/Topic1427835-391-1.aspx


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1428006
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse