March 7, 2013 at 2:02 am
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.
March 7, 2013 at 2:13 am
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.
March 7, 2013 at 2:32 am
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.
https://sqlroadie.com/
March 7, 2013 at 8:03 am
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 Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply