Solved

Convert process flow to script

Posted on 2014-03-27
1
230 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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how the fundamental information of how to create a table.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now