YouTube2Text

SQL Server Integration Services (SSIS) Part 10 - Sequence Containers and FOR Loops — Transcript

by WiseOwlTutorials · 2,810 words · 408 segments · language en · Watch on YouTube

Full transcript

  1. 0:00[Music]
  2. 0:00welcome to this wise hour tutorial on
  3. 0:02using sequence containers and for Loops
  4. 0:04within integration
  5. 0:06Services here's what you'll learn in the
  6. 0:09tutorial we'll Begin by having a look at
  7. 0:11sequence containers so we'll have a look
  8. 0:13at the task host container the default
  9. 0:16container for everything you add to a
  10. 0:17package then we'll look at how sequence
  11. 0:19containers work and finally we'll look
  12. 0:21at an example of a sequence
  13. 0:23container we'll then go on to look at
  14. 0:25for Loops so we'll see what for Loops do
  15. 0:28and then look at a practical example of
  16. 0:30a for Loop to list out all the prime
  17. 0:32numbers so let's get
  18. 0:34[Music]
  19. 0:37started before we have a look at
  20. 0:38sequence containers what they are and
  21. 0:41why you might want to use them let's
  22. 0:42first have a look at something called
  23. 0:43the task host container which is the
  24. 0:46name given to the entire
  25. 0:50package to show you the constraints is
  26. 0:52puts on what you do let's try adding a
  27. 0:55couple of data flow tasks there's one
  28. 0:59and there's another
  29. 1:00and what you'll see is it automatically
  30. 1:02gives the second task a different name
  31. 1:05and that's because task names have to be
  32. 1:07unique within the container and if I
  33. 1:10were to try renaming the second task to
  34. 1:12data flow task as well when I click
  35. 1:14somewhere else it will give me an error
  36. 1:16and tell me that another object in the
  37. 1:18collection already uses this
  38. 1:21name so you can't have two tasks with
  39. 1:23the same
  40. 1:24name in addition to that it won't
  41. 1:27surprise you to know that you can't have
  42. 1:29two VAR variables with the same name
  43. 1:31either so if I call my first variable
  44. 1:33there I which is going to hold an
  45. 1:36integer if I then had another variable
  46. 1:39and try calling that one I as well you
  47. 1:41can see that when I try to move off it
  48. 1:43it gives me the same sort of error
  49. 1:45message and tells me I can't have two
  50. 1:46variables with the same name within the
  51. 1:49task host
  52. 1:50container what I'm going to do now is
  53. 1:53show you how you can overcome this
  54. 1:55constraint by using something called
  55. 1:57sequence containers which independent
  56. 1:59boxes Each of which can have their own
  57. 2:02tasks and their own variables so let's
  58. 2:04move on to
  59. 2:05[Music]
  60. 2:07that what I'm going to do now is to add
  61. 2:10in a couple of sequence containers you
  62. 2:13can do that by dragging the sequence
  63. 2:16container task from the ssis
  64. 2:19toolbox I'll call my first one box
  65. 2:23a showing a singular lack of
  66. 2:26imagination and what I'm going to do is
  67. 2:29copy that task
  68. 2:31and then excuse me and then paste it and
  69. 2:34guess what I'm going to call the second
  70. 2:35one you guessed it box B so now I've got
  71. 2:39my two separate sequence sequence
  72. 2:41container tasks what I want to do is
  73. 2:43prove that each task that you add within
  74. 2:46that is independent of any other
  75. 2:50sequence container so I'll just make my
  76. 2:52containers a bit bigger so I can fit
  77. 2:53things into
  78. 2:54them I'm going to add two data flow
  79. 2:57tasks into box a I could have used any
  80. 2:59any task I like for this to illustrate
  81. 3:01it that's just the one at the top of the
  82. 3:03list there's the first and there's the
  83. 3:06second and as before it gives each task
  84. 3:09a distinct name because within the
  85. 3:11sequence container all the tasks have to
  86. 3:14have unique
  87. 3:15names but if I now try adding data flow
  88. 3:18task to box B you'll see that it's quite
  89. 3:21happy to give the first task I add a
  90. 3:24name data flow task which is identical
  91. 3:26to a name in another sequence container
  92. 3:30and what this shows is that each
  93. 3:31sequence container is completely
  94. 3:35independent the same thing applies to
  95. 3:37variables so if I go down to my
  96. 3:39variables what I'm going to do is add a
  97. 3:42new variable and I'm going to call it J
  98. 3:45to show an integer and set it equal to
  99. 3:48the value of
  100. 3:49one if I were to add another variable
  101. 3:51called J it wouldn't let me because the
  102. 3:54scope of that is limited to the entire
  103. 3:56package which I've called containers
  104. 4:00what I'm going to do is change the scape
  105. 4:01of this variable by moving it it's not a
  106. 4:03particularly good
  107. 4:05name but what I'm going to do is move it
  108. 4:08to box a rather alarmingly it will
  109. 4:11disappear but that's because I don't
  110. 4:13have box a selected if I now click on
  111. 4:16that box a and display my variables
  112. 4:19which I'll just pin that you'll see that
  113. 4:21the variable called J has appeared if I
  114. 4:23click off it it disappears again and
  115. 4:26that's because the scope of it is
  116. 4:27limited to the sequence container called
  117. 4:29box a
  118. 4:31I can do the same trick to create
  119. 4:32another variable which I'll also call J
  120. 4:35this time I'll set it to a value of two
  121. 4:37and it's let me do this because the
  122. 4:39scope of the second variable is the
  123. 4:40entire package and the scope of the
  124. 4:42first one is limited to the Box a
  125. 4:45sequence
  126. 4:46container I could do the same trick to
  127. 4:48move the second
  128. 4:50variable to box B and what I've now got
  129. 4:53it appears is no variables whatsoever
  130. 4:56but when I click on each sequence
  131. 4:57container you can see that it pops up
  132. 4:59with each variable the first one is got
  133. 5:01the value of one and the second one has
  134. 5:04got the value of
  135. 5:05[Music]
  136. 5:06two what I want to do now is give a very
  137. 5:09simple example of how you might use the
  138. 5:11sequence container in
  139. 5:13practice I've got a simple package here
  140. 5:16and what it does is deletes rows from
  141. 5:18three tables and then from an Excel
  142. 5:21workbook of X Factor finalist with which
  143. 5:23regular viewers will be quite familiar
  144. 5:25it Imports three worksheets the list of
  145. 5:27the people contestants the list of the
  146. 5:29series and the list of the
  147. 5:31mentors having imported those three
  148. 5:34worksheets into three different tables
  149. 5:36what it then does is take the workbook
  150. 5:38and copies it to another folder and if I
  151. 5:41run that package you'll see it chugging
  152. 5:43away and finishing so it's
  153. 5:46working it's not too important what the
  154. 5:48package does but what I want to
  155. 5:49emphasize is that these three tasks
  156. 5:53should all have to run before I can copy
  157. 5:55the finless workbook but there's
  158. 5:57actually no particular reason that they
  159. 5:59should run in this sequence it doesn't
  160. 6:00matter what order they
  161. 6:02happen if I was creating this package I
  162. 6:04think a neatest solution would be
  163. 6:07this create a sequence
  164. 6:11container and let's call it
  165. 6:15import
  166. 6:17tables and then take these three tasks
  167. 6:21and drag them into the sequence
  168. 6:23container now as it happens when I do
  169. 6:25that it's not going to work the message
  170. 6:27is coming up with is saying I have to
  171. 6:29remove the precedence constraint before
  172. 6:31proceeding so what I'll need to do is
  173. 6:33break the links between those three
  174. 6:34tasks and the outside
  175. 6:38world and then I'll be able to add drag
  176. 6:41the three tasks into the sequence
  177. 6:43container what I can then do is take the
  178. 6:46first
  179. 6:47task and feed it into the import tables
  180. 6:51one and then feed the output of the
  181. 6:53input tables one into the final copy
  182. 6:56file
  183. 6:57task the final thing I'll be temped to
  184. 6:59do is to break the links between my
  185. 7:03three
  186. 7:05Imports there's actually no particular
  187. 7:07reason that I should import the data in
  188. 7:08this order it doesn't matter and by
  189. 7:11breaking the links the multi-threading
  190. 7:13nature of ssis will allow it to uh
  191. 7:16schedule these tasks in the most
  192. 7:17efficient
  193. 7:18way if I then run this package again you
  194. 7:22should see that it does exactly the same
  195. 7:23thing as it did before and you'll have
  196. 7:26to take that on
  197. 7:27trust but you can see it's finished
  198. 7:30the beauty of it is is that these three
  199. 7:32tasks have been confined to a sequence
  200. 7:35container so I've got more control over
  201. 7:37when they
  202. 7:38run it also of course allows me to move
  203. 7:40that around anywhere I like on the
  204. 7:42screen and the three tars contained
  205. 7:44within it will follow
  206. 7:46[Music]
  207. 7:49it what I want to do now is show a
  208. 7:51particular type of container called a
  209. 7:53four Loop container they're not actually
  210. 7:56that useful four each Loop containers
  211. 7:58are far more useful ful and they allow
  212. 8:00you to iterate over files and Records
  213. 8:02but we'll cover those in a later
  214. 8:04tutorial for now let's just look at the
  215. 8:06humble for
  216. 8:07Loop what I'll do is add one of those
  217. 8:09tasks into my package and rename it to
  218. 8:13count from one to 10 and that's actually
  219. 8:18an indication of what the loop is going
  220. 8:19to do it's probably the least ambitious
  221. 8:22package I've ever
  222. 8:23written in order to be able to count I
  223. 8:25need a variable to hold the counter so
  224. 8:28I'll add a variable
  225. 8:30and I'll call it I nice short name and
  226. 8:33it doesn't actually matter what value it
  227. 8:35will hold initially because the for Loop
  228. 8:37will overwrite
  229. 8:38it there's a Red Cross which tells me I
  230. 8:41haven't yet configured my for Loop so
  231. 8:43what I can do is double click on the
  232. 8:44symbol at the top left and set three
  233. 8:47things the initial expression the assign
  234. 8:50expression and the evaluation expression
  235. 8:52and probably I'll do it in that order
  236. 8:55the initial expression is I want to set
  237. 8:56the value of the variable called I equal
  238. 8:58to one
  239. 9:00you'll notice there's yet another way of
  240. 9:02referring to variables this time I can
  241. 9:04proceed in them with the at sign it's
  242. 9:07very similar to how it works in SQL for
  243. 9:09those who know that my assigned
  244. 9:11expression each time around the loop
  245. 9:13will take the value of the variable
  246. 9:14called I and set it equal to one more
  247. 9:18than it used to be and that's a standard
  248. 9:21programming convention to get a variable
  249. 9:22to increase by one each time around a
  250. 9:25loop what I now need to do is to set
  251. 9:27something called the evaluation
  252. 9:28expression
  253. 9:30which specifies an expression that will
  254. 9:31stop the leap when the expression
  255. 9:33evaluates to
  256. 9:34false so what I'll do here is say that
  257. 9:37the variable called I has to be less
  258. 9:39than
  259. 9:4010 and so what it'll do is set the
  260. 9:42variable to one increase it by one each
  261. 9:44time around the leap and keep going for
  262. 9:46as long as it's less than 10 so if I
  263. 9:48choose okay let's try running that I
  264. 9:51think it's going to be a bit
  265. 9:52disappointing because while it runs
  266. 9:53there's actually no evidence that it did
  267. 9:55anything useful so what I'll do this
  268. 9:57time is right click on the for Loop and
  269. 10:01set break points edit break points and
  270. 10:05what I'm going to do is add a break
  271. 10:06point to the on poost execute event and
  272. 10:09what that means is when the this
  273. 10:10particular task is finished executing it
  274. 10:13will take me into debug mode so I can
  275. 10:14inspect the value of my variable if I
  276. 10:17run it again now the same thing will
  277. 10:19happen but this time you can see the
  278. 10:20yellow arrow shows it's paused and what
  279. 10:23I can now do is have a look at my locals
  280. 10:27window for example debug windows
  281. 10:29locals and you can see there's my
  282. 10:32variable called I and it has a value 10
  283. 10:35so it was increased once each time
  284. 10:37around the loop until it reached a value
  285. 10:39which was no longer less than
  286. 10:4110 so that's a simple for Loop what I'll
  287. 10:45do is just finish running it or rather
  288. 10:47abort it and what we'll do now is look
  289. 10:50at a practical example of
  290. 10:51[Music]
  291. 10:54this what I'd like to do now is to show
  292. 10:56a slightly useful example of a for Loop
  293. 10:58in practice ice I've got a package here
  294. 11:01what it will do is leop over all the
  295. 11:02Primes or rather all the numbers for
  296. 11:04each integer it will test if it's Prime
  297. 11:06and if it is it will add it to the list
  298. 11:08and the end result will be a script
  299. 11:10which will display the value of the
  300. 11:11first n primes here I've Set n to be 100
  301. 11:14or at least I'm testing all the integers
  302. 11:15up to 100 if I run that package you'll
  303. 11:18see the output of it is a list of all
  304. 11:20the Primes 2 35 7
  305. 11:24Etc what I'll now do is show you how we
  306. 11:27did that so I'll just close that down
  307. 11:28and go back back to one I've partially
  308. 11:30created earlier this already creates the
  309. 11:33script to the bottom which will display
  310. 11:35the output of the final message what it
  311. 11:37doesn't do is contain either any
  312. 11:38variables or the for Loop itself so the
  313. 11:41first thing I need to do is create three
  314. 11:43variables the first one I'm going to
  315. 11:45call test number and that will be the
  316. 11:47integer I'm testing to see if it's
  317. 11:49Prime the second variable I'm going to
  318. 11:52call Max number and that will be the
  319. 11:55highest number I'm going to go up to so
  320. 11:56I'm going to test the first 100 numbers
  321. 11:58so that we're not here all day and the
  322. 12:01third variable I'm going to call Prime
  323. 12:03string and that will be a string
  324. 12:04variable which I will initialize to two
  325. 12:08and the reason for that is I want to
  326. 12:10begin assuming that two is non Prime and
  327. 12:12test only the odd numbers to speed
  328. 12:14things
  329. 12:15up having created those variables what I
  330. 12:17can now do is to create my for Loop so
  331. 12:20I'll add that in here and I'll call it
  332. 12:23test
  333. 12:25primes and I'll configure
  334. 12:27it to say that the initial expression
  335. 12:30should be that the test number should be
  336. 12:32three I'm going to start with the first
  337. 12:34odd number the assign assign expression
  338. 12:38should be that each time around the loop
  339. 12:39I'll set the test
  340. 12:41number to be two more than it used to be
  341. 12:44so I'll test all the odd numbers 357 Etc
  342. 12:48and the evaluation expression is that
  343. 12:50I'll keep going until the test number is
  344. 12:52less than equal to the maximum number
  345. 12:54specified which in this case is
  346. 12:57100 what I then need to do is add a
  347. 12:59script within the for Loop and what this
  348. 13:02will do is test if Prime so it'll test
  349. 13:06each number to see if it's
  350. 13:08Prime I double click on that I need to
  351. 13:10pass in two variables as a readon
  352. 13:13variable I need to pass in the number
  353. 13:16I'm testing to see if it's prime
  354. 13:18otherwise the script won't know what it
  355. 13:19is it's
  356. 13:20testing and as a righton variable I need
  357. 13:23to modify the prime string so I need to
  358. 13:26add a prime to the string if it is inde
  359. 13:30Prime what I can then do is edit my
  360. 13:33script and I've got something in my
  361. 13:36clipboard I hope so if I just paste it
  362. 13:39in there I'm not especially proud of
  363. 13:41this what it will do is find out what
  364. 13:43the number is and then what it does is
  365. 13:45loop from create a variable called I and
  366. 13:49Loops from two all the way up to the
  367. 13:51maximum number I'm test the number I'm
  368. 13:53testing which in this case is test
  369. 13:55number the percent symbol divides the
  370. 13:58number I'm testing ing by an integer and
  371. 14:02looks at the remainder of it and if that
  372. 14:04remainder is zero you can assume the
  373. 14:05number was perfectly divisible and it's
  374. 14:07not prime if we get all the way through
  375. 14:10that Loop just clear that and we haven't
  376. 14:14found it it's not
  377. 14:16prime it must be Prime in which case we
  378. 14:20add the number onto the end of the
  379. 14:23string and then end the script
  380. 14:31what I now need to do is just to connect
  381. 14:34those two tasks
  382. 14:36up the second script passes in the
  383. 14:40highest number and the prime
  384. 14:44string and just displays it and you'll
  385. 14:46see in
  386. 14:48here there's just a message box
  387. 14:50displaying the message primes up to this
  388. 14:52number are couple of carriage returns
  389. 14:55and then the list of primes we built
  390. 14:57up so what we now need to do see if this
  391. 14:59actually works to make it fair I'll set
  392. 15:01it to be the startup object so you can
  393. 15:03see there's no trickery going on and if
  394. 15:05I now execute that package you should
  395. 15:08see that it lists out all the
  396. 15:14Primes and that completes this look at
  397. 15:16four Loops what I would do now is to go
  398. 15:19on to look at some of the tutorials on
  399. 15:21four each Loops there's a couple there's
  400. 15:23one on files and one on records because
  401. 15:25they're far more useful in practice now
  402. 15:27we've got the basic idea in
  403. 15:30place you can find loads more training
  404. 15:33resources on integration Services other
  405. 15:35aspects of SQL server.net and Microsoft
  406. 15:38Office at
  407. 15:40www.wis .co.uk
  408. 15:42[Music]

About this transcript

This page contains the full transcript of SQL Server Integration Services (SSIS) Part 10 - Sequence Containers and FOR Loops by WiseOwlTutorials, generated from the public captions YouTube serves with the video. The transcript has 2,810 words across 408 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.