SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


sql server stored procedure logic problem


sql server stored procedure logic problem

Author
Message
asranantha
asranantha
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1036 Visits: 4717
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.
marcel.eppel
marcel.eppel
SSC Rookie
SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)

Group: General Forum Members
Points: 37 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.
Arjun Sivadasan
Arjun Sivadasan
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1332 Visits: 976
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.
Sean Lange
Sean Lange
SSC Guru
SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)

Group: General Forum Members
Points: 63508 Visits: 17966
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.

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)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search