YouTube2Text

SQL Server Integration Services (SSIS) Part 6 - Expressions — Transcript

by WiseOwlTutorials · 3,631 words · 509 segments · language en · Watch on YouTube

Full transcript

  1. 0:00welcome to this wise tutorial on using
  2. 0:02Expressions within a SQL Server
  3. 0:04integration
  4. 0:05Services here's what you'll learn in the
  5. 0:08tutorial we'll begin with a look at the
  6. 0:10example used for this tutorial then go
  7. 0:13straight into creating basic
  8. 0:15Expressions we'll then look at some more
  9. 0:17advanced Expressions before going on to
  10. 0:20look in more detail at the Turner
  11. 0:22operator or the question mark
  12. 0:24symbol we'll then look at how to create
  13. 0:26expression tasks in integration services
  14. 0:29and finally look at how to complete your
  15. 0:31project so that you can see it working
  16. 0:34so let's get
  17. 0:36started before we look at expressions in
  18. 0:39detail I thought it would be useful to
  19. 0:40see where I'm trying to get to we're
  20. 0:43aiming to create a package with two
  21. 0:45tasks one will be something called an
  22. 0:48expression task to work out a message I
  23. 0:50want to display on screen and then I'll
  24. 0:52actually use a script task to show that
  25. 0:55message so if I run this package you
  26. 0:58should see that it displays my required
  27. 1:00message which is whether it's a weekend
  28. 1:02or not and how many days there are till
  29. 1:05Christmas a rather strange example but
  30. 1:07it will be useful for showing the
  31. 1:09various ways in which you can use
  32. 1:10expressions in integration
  33. 1:15Services before creating some
  34. 1:17expressions in integration Services I
  35. 1:19thought I'd have a quick look at where
  36. 1:20the language fits into the Microsoft
  37. 1:22Lang programming language family you've
  38. 1:25got the existing languages in Microsoft
  39. 1:27you've got C SQL vbm VBA and there's
  40. 1:31also um an element of new programming
  41. 1:33within
  42. 1:35ssis so that's where ssis Expressions
  43. 1:38fit in I would say they're mostly based
  44. 1:41on C sharp or C there's an elements of
  45. 1:44SQL in there and there's new things
  46. 1:46which Microsoft programmers probably
  47. 1:48weren't have seen before what there
  48. 1:49isn't is any VB or
  49. 1:52VBA so with that as background let's
  50. 1:54have a look at creating our first
  51. 1:58variables and set expressions for their
  52. 2:01values you can create the variables
  53. 2:04window or make it appear by clicking on
  54. 2:06the little blue eraser symbol at the top
  55. 2:07right there and what I'm going to do is
  56. 2:09create two variables one of them is
  57. 2:12going to hold the current date and one
  58. 2:14of them is going to hold the current
  59. 2:16year and we'll use these later to
  60. 2:18calculate the Expressions saying whether
  61. 2:19it's a weekend or not and how many
  62. 2:21shopping days there are till Christmas
  63. 2:24so to create the first variable I can
  64. 2:25click on the blue eraser I'm going to
  65. 2:27call this one current date
  66. 2:30and because it's holding a a date I can
  67. 2:34just type in a d or I could have clicked
  68. 2:35on the drop arrow and chosen the data
  69. 2:37type from there now instead of typing a
  70. 2:40value in for this I want it to be an
  71. 2:41expression which always gives me today's
  72. 2:43date so I can click on the three dots to
  73. 2:46the right of which is called an
  74. 2:47Expression
  75. 2:48Builder and build up my expression from
  76. 2:52the list there's two parts there's a
  77. 2:55list of variables on the left hand side
  78. 2:57at the moment i' only I've only got the
  79. 2:58one and there's a list of functions on
  80. 3:01the right now I want to show today's
  81. 3:03date so it's a fair bet it's going to
  82. 3:05belong to datetime functions so if I
  83. 3:08expand that you can see that there's a
  84. 3:10fairly small number of date functions
  85. 3:13and the one I want is get date if I let
  86. 3:15my mouse linger over it it says it
  87. 3:17Returns the current data of the system
  88. 3:19and it also comes up with a
  89. 3:21description what does take a bit of
  90. 3:23getting used to is the fact that when I
  91. 3:24double click on that it doesn't put it
  92. 3:26into the expression at the bottom what I
  93. 3:29have to do instead is click on it and
  94. 3:30drag it into the expression for that to
  95. 3:33work so I've now got an expression and
  96. 3:36if I click on this button saying
  97. 3:37evaluate expression it will tell me
  98. 3:40whether it's valid and you can see I'm
  99. 3:41creating this on the 11th of November
  100. 3:442013 at 11:07 in the morning so there's
  101. 3:48a bit of um familiarity for
  102. 3:50you if you then choose okay I've created
  103. 3:53my first variable what I'm now going to
  104. 3:55do is create a second variable which is
  105. 3:57going to hold the current year
  106. 4:00so to do this I can choose to add a
  107. 4:02variable I'm going to call this one
  108. 4:05current year and it's going to hold an
  109. 4:07integer because it's a number of the
  110. 4:10year what I can then do as before is
  111. 4:13click on the Expression
  112. 4:14Builder again I'm looking for a date
  113. 4:16function fairly obviously and in this
  114. 4:19case I want one which will give me the
  115. 4:21year corresponding to a date so I can
  116. 4:23click on that drag it down into the
  117. 4:26expression now the bit in the middle
  118. 4:29there says that it expects a date to be
  119. 4:32filled in as the one argument to it but
  120. 4:35what I can do is click on get date uh
  121. 4:39sorry is go to the variables click on
  122. 4:42current date which holds today's date
  123. 4:45and I can drag it down over that
  124. 4:46argument now watch what happens when I
  125. 4:48get over it the argument is selected in
  126. 4:51its entirety and when I release the
  127. 4:53mouse button what it will do is replace
  128. 4:55that argument with the name of the
  129. 4:57variable you can see the name of the the
  130. 4:59variable is a bit long-winded it's got
  131. 5:01an at symbol then it's got user to
  132. 5:04signify it's a user variable and not a
  133. 5:06system one and then it's actually got
  134. 5:07the name of the
  135. 5:08variable so I can click and evaluate
  136. 5:11expression to see the value of this and
  137. 5:13it says I'm in
  138. 5:142013 and if I choose okay it will also
  139. 5:17show the value in Gray there so that's
  140. 5:20how you can create simple Expressions
  141. 5:23what we'll now do is go on to look at
  142. 5:24some more complicated
  143. 5:27ones what I now want to do is three new
  144. 5:30Expressions to give how many days there
  145. 5:32are from now until Christmas I'm going
  146. 5:34to do this in three stages to make it
  147. 5:36clearer what's going on and to show how
  148. 5:38to use expressions in
  149. 5:40ssis the first variable I'll create will
  150. 5:43give the date of Christmas Day for this
  151. 5:46year but as a string of text so will
  152. 5:49evaluate to the 25th of December
  153. 5:512013 but that will be a string of text
  154. 5:54and I'll use that format because I know
  155. 5:56that ssis can convert that to a date
  156. 5:58format
  157. 6:00what we'll then do is calculate what
  158. 6:02that is as a date so we'll convert it to
  159. 6:04a datetime format and finally I'll take
  160. 6:07the difference between today's date and
  161. 6:09that date to work out that at the time
  162. 6:11of writing there's 49 days till
  163. 6:14Christmas but I've hardcoded all of
  164. 6:16those three variables in what I need to
  165. 6:18do is create Expressions to calculate
  166. 6:20them according to the current date so
  167. 6:22let's start with the date of Christmas
  168. 6:25as a in text format so I'll create a new
  169. 6:28variable and I'm going to call it exus
  170. 6:31date text and it's going to be a string
  171. 6:35variable because it's going to hold a
  172. 6:37series of characters and if I click on
  173. 6:39the Expression Builder what I need to do
  174. 6:41then is build it
  175. 6:43up what I would like to do is this I'd
  176. 6:46like to take the current here the
  177. 6:48variable I've already calculated which
  178. 6:50will give me the
  179. 6:5120113 and what I'd like to do is
  180. 6:54concatenate that with the month and the
  181. 6:57day the concatenation symbol is a plus
  182. 7:00sign which will be familiar to anyone
  183. 7:02who writes in SQL or C but may give VB
  184. 7:05programmers cause for
  185. 7:08concern what I can then do is add
  186. 7:11on the month and the year so starting
  187. 7:14with the most General thing the year and
  188. 7:16going to the most specific thing the day
  189. 7:19the problem is if I evaluate that
  190. 7:21expression it will give me an error and
  191. 7:23what is saying is that the data types
  192. 7:25DTI 4 and DT wst are incompatible
  193. 7:30and that's because I'm trying to
  194. 7:31concatenate or join together two things
  195. 7:33one of which is text but the other of
  196. 7:35which is an integer an ssis is extremely
  197. 7:39fussy about its data types so what I
  198. 7:42need to do is convert this first thing
  199. 7:44to text and I can do that by looking at
  200. 7:48the typ cast functions casting is just a
  201. 7:52posh word for converting data types so
  202. 7:55if I expand that you can see for every
  203. 7:57single data type in ssis there's a
  204. 8:00corresponding conversion function the
  205. 8:02one I want is something which will take
  206. 8:04this and turn it into text and I've got
  207. 8:06two choices dtor St or dtore
  208. 8:12wstr I'm going to go for the second
  209. 8:14choice because it's simpler with the
  210. 8:17first one I'd have to specify the code
  211. 8:19page whereas with the second one I can
  212. 8:21just specify how long the text is or
  213. 8:24rather should be so I can drag that
  214. 8:27before the expression and change the
  215. 8:29length
  216. 8:31to be four characters because that's how
  217. 8:33many characters are in a string of text
  218. 8:35and when I evaluate that it will give me
  219. 8:37the data's
  220. 8:39text for VB programmers and indeed for
  221. 8:42SQL ones it may seem strange that you
  222. 8:44put the conversion function before the
  223. 8:46variable you're
  224. 8:47converting but as my daughter would say
  225. 8:50you'll have to cope with that um it's
  226. 8:52just how it works in ssis and also how
  227. 8:55it works in C by the
  228. 8:57way so we choose okay to confirm that
  229. 9:00and what I'm now going to do is create a
  230. 9:02second expression to give the date of
  231. 9:05Christmas so to do that I can add
  232. 9:07another expression I'll call it xmus
  233. 9:10date it's going to be a datetime
  234. 9:13expression and this time all I want to
  235. 9:15do is take the text of the Christmas
  236. 9:17date and convert it into a datetime
  237. 9:20format so again I'm looking for a type
  238. 9:22Cass function and the one I'm going to
  239. 9:24choose is dtore DB time stamp which will
  240. 9:29convert a string of text into a datetime
  241. 9:31format so I can drag that into the
  242. 9:34Expression
  243. 9:35Builder and then I can put in the thing
  244. 9:37I'm actually trying to convert which is
  245. 9:40the xmus data's
  246. 9:43text and if I click on evaluate
  247. 9:45expression what it will do is give me
  248. 9:47the date in a date format which is what
  249. 9:50I wanted and because I haven't specified
  250. 9:52a time it assumes it's midnight just
  251. 9:55when children are starting to open their
  252. 9:56presentence perhaps so if I choose okay
  253. 9:59to confirm that I've got one more
  254. 10:01variable to create in this session and
  255. 10:03that will give me how many days there
  256. 10:04are till Christmas so I can add another
  257. 10:07variable I'm going to call this one xmus
  258. 10:10days and it's going to be an
  259. 10:13integer and to calculate this I need to
  260. 10:16work out the difference between two
  261. 10:18dates one of them is today's date which
  262. 10:21is held in a variable called current
  263. 10:24date and one of them is the date of
  264. 10:26Christmas
  265. 10:27day I could do this by subtracting one
  266. 10:30from the other but there's a posher
  267. 10:32better function in ssis which is the
  268. 10:35date diff function the difference
  269. 10:37between data ad and date diff is a data
  270. 10:40ad takes a date and adds on a given
  271. 10:41number of days weeks months quarters
  272. 10:43years whatever it may be whereas date
  273. 10:46diff takes the difference between two
  274. 10:48dates and you can see it says that in
  275. 10:50the
  276. 10:51description so I can drag that in I'll
  277. 10:55come back to the first argument at the
  278. 10:56end for the moment let's choose the
  279. 10:58start date and the end date the start
  280. 11:01date is today's date so I can drag that
  281. 11:04over the start date and the end date is
  282. 11:07a date of Christmas Day
  283. 11:09itself now the question is taking the
  284. 11:12difference between those two dates do I
  285. 11:14want to say how many months there are
  286. 11:15between them how many quarters how many
  287. 11:17years how many weekdays or in this case
  288. 11:19how many days and the only practical way
  289. 11:22I can think of finding out what you
  290. 11:23should type in in this um argument is to
  291. 11:27go on Google or use help but I've done
  292. 11:31that and I know I want to take how many
  293. 11:32days there are so I can evaluate that
  294. 11:35expression and it will give me 49 the
  295. 11:38number of days between the two dates so
  296. 11:41I can then choose okay to confirm that
  297. 11:43and that completes my three
  298. 11:47Expressions the last variable we're
  299. 11:49going to create before we get into
  300. 11:51creating expression tasks is want to say
  301. 11:53whether it's a weekend or not so I've
  302. 11:56created an example here which will say
  303. 11:58it's a week weekend I'm actually
  304. 12:00recording this on a Wednesday so in fact
  305. 12:03when I create my expression it will say
  306. 12:04the opposite it will say that it's a
  307. 12:07weekday the to do this we're going to
  308. 12:09use something called the Turner operator
  309. 12:12which involves writing a condition then
  310. 12:15putting a question mark then putting
  311. 12:17what will happen if the condition turns
  312. 12:18out to be true then putting a colon and
  313. 12:22then putting what uh you what will
  314. 12:23happen if the condition turns out to be
  315. 12:26false VB and probably access other
  316. 12:29programmers will recognize this as the
  317. 12:32if or the iif function but there's no
  318. 12:35function like that in ssis so instead
  319. 12:38you have to use a thing called a turn
  320. 12:39Turner
  321. 12:41operator so let's have a go of creating
  322. 12:43this expression so I'll choose to create
  323. 12:45a new
  324. 12:46variable excuse me and I'll call it
  325. 12:49weekend
  326. 12:52status and it's going to be a string
  327. 12:55variable and is going to have an
  328. 12:58expression so the first thing I'm going
  329. 13:00to do is to put in my condition which is
  330. 13:03in this case whether the weekday is a
  331. 13:07Saturday or a
  332. 13:08Sunday now the way I'm going to do that
  333. 13:10is having search for a weekday function
  334. 13:13here and not found it I'm going to do
  335. 13:15the next best thing and use the date
  336. 13:17part function which gives you an integer
  337. 13:20representing a date part of a date now
  338. 13:22that date part could be the day number
  339. 13:24the month number the week number the
  340. 13:26year number or as in this case the week
  341. 13:29day number so if I drag that
  342. 13:31in the date I want to use is the current
  343. 13:35date so that's nice and easy for the
  344. 13:37date part it's back to Google or back to
  345. 13:40help again in this case what I actually
  346. 13:42want to type in is DW in quotation marks
  347. 13:46which will give me the weekday number
  348. 13:48and by default weekdays start from uh
  349. 13:52Monday so in fact because it's a
  350. 13:54Wednesday that will give me the number
  351. 13:56three so what that's my stter my
  352. 13:59condition what I now want to say is
  353. 14:01whether that equals 6 or seven six being
  354. 14:06Saturday 7 being Sunday and to do that I
  355. 14:10can use an
  356. 14:12operator and my operator in this case is
  357. 14:15equals and I can drag that in now I
  358. 14:18could of course have typed that in much
  359. 14:20more easily but I was doing it to
  360. 14:21emphasize the fact that in ssis unlike
  361. 14:24in some other languages you have to put
  362. 14:26the equal sign twice in a condition
  363. 14:29so if that's
  364. 14:31six I would now want to say or and again
  365. 14:34if you're having problems remembering
  366. 14:35the syntax the easiest thing to do is go
  367. 14:37to the list of operators and you can see
  368. 14:39that and is written as Ampersand
  369. 14:41Ampersand and or is written as two
  370. 14:43vertical bars one after the other so I
  371. 14:46could either type that in or drag it
  372. 14:48in so either that equals six or that
  373. 14:53equals seven and what I'm going to do is
  374. 14:55indulge in a bit of copying and pasting
  375. 14:57to save myself typing
  376. 14:59and there's my
  377. 15:02condition what I'm now going to do is
  378. 15:04say if that's true then what I want to
  379. 15:07do is put in a message saying it's a
  380. 15:09weekend and I've put in some return
  381. 15:12codes to make my expression easier to
  382. 15:13read they'll be ignored by
  383. 15:16ssis so if that's true I want to say
  384. 15:19it's the
  385. 15:21weekend and I think that deserves an
  386. 15:23exclamation
  387. 15:24mark otherwise I'm going to put a
  388. 15:27message saying
  389. 15:29it's a
  390. 15:31weekday and if I evaluate that
  391. 15:33expression it will tell me it's a
  392. 15:35weekday because as I've mentioned I'm
  393. 15:37recording this on a
  394. 15:38Wednesday so I can choose okay to
  395. 15:40confirm that and that is how to create a
  396. 15:43Turner operator so just as a refresher
  397. 15:46there you put in the condition excuse me
  398. 15:49you put the condition you put a question
  399. 15:51mark you put what happens if that's true
  400. 15:53then you put a colon and then you put
  401. 15:55what happens if that isn't true
  402. 16:00for the final part of this tutorial
  403. 16:02we're going to create and display the
  404. 16:04message saying whether it's a weekend or
  405. 16:06not and how many days or are till
  406. 16:08Christmas as a first step I'll create a
  407. 16:11variable which I'll call message to hold
  408. 16:13a string of text now what I could do is
  409. 16:16use expression Builders before to build
  410. 16:17up this message but by way of variation
  411. 16:21I'm going to instead use an expression
  412. 16:23task now if you can't see this it's
  413. 16:25because you're not using the latest
  414. 16:26version of SQL Server it's quite a new
  415. 16:28new addition so I can add that task into
  416. 16:31my control flow window and perhaps
  417. 16:34change the name of it so it does says
  418. 16:35something more sensible what it's going
  419. 16:37to do is calculate the message to be
  420. 16:39displayed so I'll call it calculate the
  421. 16:43message as with any other task I can
  422. 16:45then double click on the icon to the
  423. 16:46left of it to configure how it's going
  424. 16:48to work and what it's going to do is set
  425. 16:50the value of my message equal to
  426. 16:54something now the first thing it's going
  427. 16:56to do is put in the weekend status so I
  428. 16:58can just drag that into the window and
  429. 17:00that will give me the bit which says
  430. 17:02whether it's a weekend or
  431. 17:03weekday what I can then do is
  432. 17:05concatenate something with that and what
  433. 17:08I now want to do is put in two Carriage
  434. 17:11returns so that there's a blank line
  435. 17:13between my first message and my second
  436. 17:15one in uh VBA you would do that by
  437. 17:18typing vbcrlf in other languages you
  438. 17:21would use YY characters 13 and 10 in
  439. 17:24ssis and indeed in C you put in a back
  440. 17:28slash n for each carriage return you
  441. 17:31want to
  442. 17:32include I can then have the words there
  443. 17:36are and what I now want to do is put in
  444. 17:39how many days there are till Christmas
  445. 17:42but it's no good just using this
  446. 17:43variable because that's an integer and I
  447. 17:45want it to be incorporated within a
  448. 17:46string of text so what I'm going to do
  449. 17:49first is to convert it to
  450. 17:52text I would have thought a maximum
  451. 17:54length of three would be sufficient
  452. 17:57because there can be most three 65 days
  453. 17:59till Christmas and then I can drag my
  454. 18:02variable
  455. 18:03in so I've now got there R followed by a
  456. 18:06number what I want to do to complete my
  457. 18:08message is just to type
  458. 18:10in days till
  459. 18:14Christmas and if I evaluate that
  460. 18:16expression it would tell me it's a
  461. 18:18weekday but if I scroll down you can see
  462. 18:21underneath that it's also got the
  463. 18:23message saying how many days are till
  464. 18:25Christmas so I can choose okay to
  465. 18:27confirm that and that completes my
  466. 18:30expression
  467. 18:32task what I'm now going to do very
  468. 18:34briefly is to explain how to display
  469. 18:37that message on screen um because this
  470. 18:39is all a refresher of things we've done
  471. 18:41in previous tutorials so the first thing
  472. 18:44I want to do is TR add a script task and
  473. 18:46then I need to make sure that it follows
  474. 18:48on directly from the calculation of the
  475. 18:50message I can double click on the script
  476. 18:52task to configure it and specify that I
  477. 18:54can pass the value of my message
  478. 18:56variable as a readon varable able into
  479. 18:59the task and then I can go straight into
  480. 19:02editing the script using the default
  481. 19:03language which is
  482. 19:06C the first and only thing it's going to
  483. 19:08do is display a message so I can type in
  484. 19:11messagebox doow and the message it will
  485. 19:14display is just a value of the variable
  486. 19:16which is part of the variables
  487. 19:18collection it's called message I need to
  488. 19:20be careful to type that in in the
  489. 19:22correct case and it's actually the value
  490. 19:24of the variable I want to display that's
  491. 19:27returned as an object so what I need to
  492. 19:29do is convert that to a string of text
  493. 19:31to make sure that it displays correctly
  494. 19:34and that's got rid of all the red
  495. 19:35underlinings so I'm pretty confident
  496. 19:37that's going to work so I can then close
  497. 19:40that down that project to return me back
  498. 19:41to my original one and choose
  499. 19:43okay and if I've done everything
  500. 19:45correctly when I play this I should get
  501. 19:47the message saying it's a weekday and
  502. 19:50there are 49 days till Christmas just
  503. 19:52time to do my shopping I hope you've
  504. 19:54enjoyed this tutorial on integration
  505. 19:56Services Expressions you can find loads
  506. 19:59more training resources on integration
  507. 20:00Services other aspects of SQL server and
  508. 20:03net and Microsoft Office at
  509. 20:06www.wis al.uk

About this transcript

This page contains the full transcript of SQL Server Integration Services (SSIS) Part 6 - Expressions by WiseOwlTutorials, generated from the public captions YouTube serves with the video. The transcript has 3,631 words across 509 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.