Solved

Convert process flow to script

Posted on 2014-03-27
1
237 Views
Last Modified: 2014-03-28
Hi all
Today is one of the days.. the brain stop processing logic

I need to do some batch process.
First I need to check if the position are completed with refrence to a header record.

I do this with a batch: exec sp_BuyersCheckPosition @TransID, @CustomerNr, @PosCheck OUTPUT      

If the position is not yet complete, I check if the time  since creation has elapse for 5 mins.
I process the batch.. If the condition is not yet met .. I will exit the execution..

Note..  If the position is complete, there is no need to check the time..  But if the position is not complete .. then check if the waiting time of 5 mins has elapse before processing the batch.


Process Flow
IF EXISTS(SELECT CreateDate FROM Customer_H 	WHERE (TransID = @TransID 
				AND  CreateDate < (select  DATEADD(mi, -2, GETDATE())) ))
				BEGIN
					@TimeCheck = 1
				END
			exec sp_BuyersCheckPosition @TransID, @CustomerNr, @PosCheck OUTPUT	
			IF (@PosCheck = 1 OR @TimeCheck = 0) 
			BEGIN
				Do my Batch thing
			End

Open in new window

0
Comment
Question by:ZURINET
1 Comment
 
LVL 35

Accepted Solution

by:
David Todd earned 500 total points
ID: 39960472
Hi,

Here is how I'd code it.

declare @isOkayToExit bit
set @isOkayToExit = 0

while not @isOkayToExit begin
	set @isOkayToExit = 1

	exec sp_BuyersCheckPosition @TransID, @CustomerNr, @PosCheck OUTPUT	

	if @PosCheck != 1 begin
		IF EXISTS(
			SELECT CreateDate 
			FROM Customer_H 	
			WHERE 
				(TransID = @TransID 
				AND  CreateDate < (select  DATEADD(mi, -5, GETDATE())) ) -- I think the dateadd should be -5 not -2
				)
		BEGIN
			@TimeCheck = 1
		END else begin
			@isOkayToExit = 0
			-- http://technet.microsoft.com/en-us/library/ms187331.aspx
			waitfor delay '0:02:00'
			continue

	end

	IF (@PosCheck = 1 OR @TimeCheck = 1) BEGIN -- I think that the check should be is @TimeCheck = 1
		--set @isOkayToExit = 1
		Do my Batch thing
	End 
end

Open in new window

Regards
  David
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question