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


Need to put select and update in a single stored procedure


Need to put select and update in a single stored procedure

Author
Message
Raghavendra-499237
Raghavendra-499237
SSC Eights!
SSC Eights! (877 reputation)SSC Eights! (877 reputation)SSC Eights! (877 reputation)SSC Eights! (877 reputation)SSC Eights! (877 reputation)SSC Eights! (877 reputation)SSC Eights! (877 reputation)SSC Eights! (877 reputation)

Group: General Forum Members
Points: 877 Visits: 351
hi all,



Let me explain my requirement briefly. I have a table called compliant which stores compliant posted by users. When a new compliant is posted, then status of that compliant will be "Opened". Similarly once the compliant is resolved by the support team they will set the status of compliant to "User to Confirm". If user is satisfied then he/she can set the compliant status into "Closed". If user missed to change status as "Closed", once it has resolved then after 48 hours compliant status should set to "Closed" and also an automated mail should sent to user regarding status of that compliant.



I have created an stored procedure which display all compliant along with user details, which are resolved before 48 hours whose status to be changed to "Closed". Now from c# application I will send mails to all those users. Then I am calling another stored procedure to update status of the compliant as "Closed", which takes compliant number as parameter.



Can anyone help me to write both sql statements (selecting compliants and updating compliant status) inside a single stored procedure? Also I want to know is it required to use transaction in my case?
ChiragNS
ChiragNS
SSChampion
SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)

Group: General Forum Members
Points: 11297 Visits: 1865
Hi



The status must be updated to "Close" only if the mail has been sent successfully right ?

If this is not the case then you can put both the select and update statements in a single procedure.



Otherwise do it separately ... This will ensure that status is updated only when a mail is sent.

"Keep Trying"
Raghavendra-499237
Raghavendra-499237
SSC Eights!
SSC Eights! (877 reputation)SSC Eights! (877 reputation)SSC Eights! (877 reputation)SSC Eights! (877 reputation)SSC Eights! (877 reputation)SSC Eights! (877 reputation)SSC Eights! (877 reputation)SSC Eights! (877 reputation)

Group: General Forum Members
Points: 877 Visits: 351
hi,



thanks for your suggestion. Status should be updated to "close" only when mail is sent. Ok I will use 2 stored procedures, is it required to use transaction (client side)
ChiragNS
ChiragNS
SSChampion
SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)

Group: General Forum Members
Points: 11297 Visits: 1865
Hi



Better use a transaction (client side). Otherwise the mail may not be sent but the status will be updated.

"Keep Trying"
Raghavendra-499237
Raghavendra-499237
SSC Eights!
SSC Eights! (877 reputation)SSC Eights! (877 reputation)SSC Eights! (877 reputation)SSC Eights! (877 reputation)SSC Eights! (877 reputation)SSC Eights! (877 reputation)SSC Eights! (877 reputation)SSC Eights! (877 reputation)

Group: General Forum Members
Points: 877 Visits: 351
Thank you very muchSmile
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