SQL Server Integration Services (SSIS) Part 16 - Expression and Other Constraints — Transcript
Full transcript
- 0:00[Music]
- 0:01Welcome to this short Weisowl tutorial
- 0:03on using precedence constraints within
- 0:05SQL Server Integration Services. Here's
- 0:08what we'll learn in the
- 0:10tutorial. We'll begin by looking at can
- 0:13normal constraints. So I'll show you how
- 0:15to get a task to run depending on the
- 0:17completion status of the previous
- 0:19one. We'll then go on to look at
- 0:21expression constraints. So, I'll show
- 0:23you how to set expression constraints
- 0:25and how to switch between them all
- 0:27having to be true or any one of them
- 0:29having to be true. So, let's get
- 0:32[Music]
- 0:34started. To explain how constraints
- 0:37work, I've created a package which asks
- 0:39the question, is cricket boring? I think
- 0:42we all know the answer to that. There's
- 0:44two possibilities, yes or no. So, if I
- 0:46try running that package, you'll see it
- 0:48comes up with a relevant question using
- 0:49a script. If I were to answer yes, which
- 0:52is a correct answer, of course, that
- 0:54would be deemed to be a success, and I
- 0:57would go down this green path, and
- 0:59you'll get a message saying you've
- 1:00chosen the correct answer. If I answer
- 1:03no, you'll instead go down the failure
- 1:05path, and you'll get a message saying
- 1:07you've chosen the wrong answer. And
- 1:09whether I answer yes or no, I'll
- 1:11automatically go down the completion
- 1:12path because the task completed and I'll
- 1:15log the fact an answer was
- 1:16given. So, let's try. Firstly, I'll say
- 1:19no, it isn't boring. That's the wrong
- 1:21answer. So, it's displayed that in a
- 1:23script going down this path. And you can
- 1:26see the task failed. If I try doing that
- 1:29again, but this time answer correctly
- 1:31and say cricket is
- 1:32boring. Then I've gone down the success
- 1:35path and got a message saying it's the
- 1:36right
- 1:37answer. Whichever I did, whether I chose
- 1:40yes or no, this log the fact an answer
- 1:42was given task completed. And in fact,
- 1:45if I now go to the log file created from
- 1:47that, which I put here, and double click
- 1:50on it, you can see the last two times I
- 1:53ran the task have been logged. It took
- 1:55me 13 seconds between one and the
- 1:57other.
- 1:59So, how did that work? Well, the is
- 2:02cricket boring script had a message box
- 2:05within it, which I'll just illustrate
- 2:07just in case you've never seen this
- 2:08before.
- 2:10And what that does is set a variable
- 2:12called answer to hold the result of a
- 2:14dialogue box and ask the question is
- 2:16cricket boring and the configuration
- 2:19buttons are that you can have a yes and
- 2:21a no button. If somebody answers yes
- 2:24then the result is deemed to be a
- 2:27success and what I did is just copied
- 2:29and pasted that script to say that
- 2:30otherwise the result would be deemed to
- 2:32be a failure. So that's how I got this
- 2:35to work. What I want to do is how show
- 2:38now how to configure these
- 2:39constraints. And to illustrate that,
- 2:42I've created a simpler version of this,
- 2:44a template version, which contains all
- 2:46the same tasks, but not joined
- 2:48together. What I then did is I dragged
- 2:51the green success arrow
- 2:54from my initial question onto the other
- 2:57three tasks.
- 2:59I then rightclicked on this one and
- 3:02chose that this logging task should run
- 3:05under all possible circumstances that
- 3:07the previous one completed and the arrow
- 3:10turns black. I then right clicked on
- 3:12this other constraint and shows that
- 3:15this should run if the previous task
- 3:17failed. So what's happening here is the
- 3:19script is determining whether it was a
- 3:21success or failure and that determines
- 3:23which path we'll go down. And to be
- 3:26honest, I think that's probably all
- 3:27there is to say about precedence
- 3:29constraints. So, we'll now have a look
- 3:30at expression constraints
- 3:34instead. To illustrate how expression
- 3:37constraints work, uh we're going to go
- 3:39back to our familiar Xactor contestants
- 3:41workbook. It's based on the popular UK
- 3:43reality TV show. And we've got three
- 3:45worksheets. We've got 109 finalists.
- 3:48We've got nine series. And we've got 10
- 3:51mentors, the people who advise the
- 3:53contestants. And what I've done is
- 3:55created a package which imports this
- 3:57information into three separate SQL
- 3:58server tables. So there's 109
- 4:01contestants. I've got my series table
- 4:03with nine series and I've got my mentors
- 4:05table with 10 mentors it. So what
- 4:08actually does this? If we have a look
- 4:11integration services here's my package.
- 4:14What it does firstly is to run an
- 4:16execute SQL task to get rid of all the
- 4:18old records. And then it runs three
- 4:20separate data flow tasks to import the
- 4:22contestants, series, and mentors at the
- 4:25same time counting how many records
- 4:26there are. It stores that information in
- 4:29three variables which I've created
- 4:30called number, contestants, number,
- 4:32mentors, and number series. And finally,
- 4:34it uses a script to display the results
- 4:36of those variables. So we can see how
- 4:38many records we've imported. And then it
- 4:40has a file system task to copy the
- 4:42workbook to another
- 4:43folder. If we have a look at one of
- 4:45these sample data flow tasks, this is
- 4:48what it does. It takes a Excel workbook
- 4:50of contestants for example, counts how
- 4:53many there are with a row count
- 4:54transform and then puts the results into
- 4:57the SQL Server
- 4:59table. So if I run that, it will all run
- 5:02completely normally because there's no
- 5:03constraints in whatsoever. And it says
- 5:06how many contestants, mentors, and
- 5:07series I've got. What I'm now going to
- 5:10do is to add constraints saying that the
- 5:12final two tasks, these bottom two, will
- 5:14only run if I have at least 100
- 5:16contestants. So far so good. at least 10
- 5:18mentors and at least 10 series. And
- 5:21because there's only nine, these bottom
- 5:23two
- 5:24tasks won't actually run. So let's do
- 5:27that. To add a constraint, or rather an
- 5:30expression constraint, you right click
- 5:31in an existing constraint and choose to
- 5:33edit it. You can then change it from a
- 5:36normal constraint to an expression one.
- 5:39And then you can specify what the
- 5:40expression should be, which has to be
- 5:42true for the next task to run. So you
- 5:45can click on the three dots. And in my
- 5:46case, I'm going to drag down the number
- 5:48contestants variable and say that it has
- 5:50to be greater greater than or equal to
- 5:53100. If I evaluate that is a bit
- 5:55misleading because the value of the
- 5:57variable is currently zero, it will
- 5:58actually give me false. But when I run
- 6:01the actual package, this variable will
- 6:03be populated with 109 and the condition
- 6:05will be true. So if I choose okay for
- 6:08that and I'm going to do the same thing
- 6:09for the other two constraints quite
- 6:11quickly. So I'm going to turn them both
- 6:13into expression tasks. This one should
- 6:15be that the number series has to be
- 6:17greater than or equal to 10. And the
- 6:19final one should be that the number of
- 6:26mentors has to be greater than equal to
- 6:3110. And you can see I've set
- 6:33constraints, expression constraints
- 6:35because of this little symbol appearing
- 6:36on each of the constraints. If I run
- 6:38this now, I wouldn't see the message at
- 6:41the end.
- 6:42And the reason for that is while two of
- 6:45these constraints were true, the third
- 6:47one wasn't. So what we're now going to
- 6:49do is look at how to make it so these
- 6:51final two tasks will run if any one of
- 6:53these constraints is
- 6:56true. In the previous part of this
- 6:58tutorial, we created three constraints
- 7:00which said that the number of
- 7:01contestants imported has to be at least
- 7:03100, series has to be at least 10, and
- 7:06the mentors has to be at least 10. But
- 7:08the problem is because only two of those
- 7:10three conditions are true, we're not
- 7:12running the last two tasks. What I want
- 7:15to do is show how to edit this so any
- 7:17one of the conditions can be true. And I
- 7:19think it's slightly surprising how it
- 7:21works. What I would expect to have to do
- 7:23is to select all three constraints at
- 7:26the same time and right click on them.
- 7:29But actually, if you do that, it doesn't
- 7:32help. The slightly surprising way you do
- 7:34it is just to select any one of them.
- 7:36And it doesn't actually matter which one
- 7:38you choose and choose to edit
- 7:40that. At the bottom where it says
- 7:42multiple constraints, I'm going to
- 7:44change it so it's a logical or one
- 7:46constraint must evaluate to true. If I
- 7:49then choose okay, you can see that it
- 7:51changes the line of all three
- 7:53constraints leading into this task to
- 7:55dotted which clearly shows that any one
- 7:57of them can be true and in that case the
- 8:00last two tasks will run. to see this
- 8:02working. Now, if I run exactly the same
- 8:04package as I did in the previous part of
- 8:06the tutorial, but with a slight change
- 8:07to the constraints, you can see that
- 8:09when I choose okay, it's run the script
- 8:11and copied the file because even though
- 8:13all three conditions weren't true, at
- 8:15least one of them
- 8:17was. And that's the end of this tutorial
- 8:19on constraints. You can find lots more
- 8:21resources on SQL Server integration
- 8:23services, SQL Server.net, and other
- 8:26Microsoft Office training at
- 8:30www.wisowl.co.uk. UK.
About this transcript
This page contains the full transcript of SQL Server Integration Services (SSIS) Part 16 - Expression and Other Constraints by WiseOwlTutorials, generated from the public captions YouTube serves with the video. The transcript has 1,560 words across 231 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.