Solved

DTS workflow branching based on query results

Posted on 2006-10-27
6
508 Views
Last Modified: 2008-02-01
I have DTS package that runs an Execute Process Task.  Prior to running the task I want to check results from a couple of queries that I have.  Basically the queries are stored views that check for missing members in certain tables.  The queries should always come back with a null result, in which case the Process Task should run, if however one of the views does return a record (1 or 1000 records, doesn't make a difference) then the Process Task should not run.
I'm figuring I need a VBscript or maybe a stored procedure, but I'm not very good with either so please give me some good ideas and provide a lot of details on how to implement.

Tanks in advance.
0
Comment
Question by:garycris
6 Comments
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 17822067
do you mean NULL or just empty / false?

sounds like you want to do an Exists/Not Exists test...

e.g.

  If not Exists ( select 'y' from View1 where ...)
    amd not exists ( select 'y' from View2 where ...)
   begin
        do what you want
   end

hth
0
 
LVL 5

Author Comment

by:garycris
ID: 17822129
An example would be I have a view called Missing_Accounts.

I want to write an ActiveX VB script that checks if the query returns any records.

If it returns records, I want to DTSTaskExecResult_Failure
If it doesn't return any records, then I want DTSTaskExecResult_Success

Thanks
0
 
LVL 5

Author Comment

by:garycris
ID: 17822361
I've been giving this more thought and I think I could just say

SELECT COUNT(*)
FROM Missing_Acocunts

and then say if the result is 0 then success if <> 0 then failure.

So how do I run a query in an active x script and capture the result to test in an IF statement?
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 11

Expert Comment

by:rw3admin
ID: 17822690
you can do
Select 1/(SELECT COUNT(*)
FROM Missing_Acocunts
)

if there are records this will succeed, if there are no records ( 0 records ) you will get 0 divided error and then you can go to your two execute process tasks on Succes and on Failure

rw3admin
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 total points
ID: 17824190
1. Create a Global Variable called MyCount data type integer.
2. Create an Execute SQL Task with:
SELECT COUNT(*) MyCount
FROM Missing_Acocunts
3. Click Parameters ...
4. Select the Output tab
5. Select Row Value option
6. Match the MyCount Parameter to the MyCount global variable.
7. Create an ActiveX Script Task and make sure to use Workflow so that it executes after the Execute SQL Task.
8. Add code as follows:
Function Main()

If  DTSGlobalVariables("MyCount").Value > 0 Then
      Main = DTSTaskExecResult_Success
Else
      Main = DTSTaskExecResult_Failure
End If

End Function
0
 
LVL 5

Author Comment

by:garycris
ID: 17836513
Exactly what I wanted.  Works perfect.

Thanks,
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

746 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

12 Experts available now in Live!

Get 1:1 Help Now