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
 count increment in stored proc

Author  Topic 

sqldoubt
Starting Member

17 Posts

Posted - 2010-06-16 : 12:47:43
Hi all,

In a stored procdure I am trying to fit in this piece of code.

to check if orderuser exists for Particular orderitem in Query OrderUser table. if not write to a errorlog table.
SELECT @UserId = [OrderUser].UserId FROM OrderUser WHERE [OrderUser].OrderId = @OrderID
Declare @RETRYCOUNT INT
SET @RETRYCOUNT = 0
IF (@UserId = NULL)
BEGIN
--But Before inserting into errorlog i also need to check if that particular orderitemid is already existing in errorlog table and then insert. Each time it checks and inserts into errorlog retry count should be incremented. And after retrycount becomes 4, it should stop checking for userid. How to do this...
INSERT INTO AdCRMMessageprocess_ErrorLog(orderId,OrderItemId,ErrorMessage,ErrorCode,RetryCount,orderstatus)
Values(@OrderID ,)
SET @RETRYCOUNT = @RETRYCOUNT + 1
END
Any help plz..

Devart
Posting Yak Master

102 Posts

Posted - 2010-06-18 : 07:53:22
Try something like this:

declare @retry_count int
set @retry_count=isnull((select max(retrycount) from AdCRMMessageprocess_ErrorLog where orderitemid=@idorderitemid),0)

IF @retry_count<4
BEGIN
SET @RETRYCOUNT = @RETRYCOUNT + 1
INSERT INTO AdCRMMessageprocess_ErrorLog(orderId,OrderItemId,ErrorMessage,ErrorCode,RetryCount,orderstatus) ...
END

Devart,
Tools for SQL Server
http://www.devart.com/dbforge/sql
Go to Top of Page
   

- Advertisement -