📺 Develpreneur YouTube Episode

Video + transcript

SQL Tutorial - Loops

2022-05-24 •Youtube

Detailed Notes

1. Loops 2. While loops 3. Repeat loops 4. Leave statement *** Please note that greater and less than brackets were removed for the YouTube notes.

DELIMITER // CREATE OR REPLACE PROCEDURE looper() BEGIN DECLARE x INT; DECLARE str VARCHAR(255);

SET x = 1; SET str = '';

my_loop: LOOP IF x 10 THEN LEAVE my_loop; END IF;

SET x = x + 1; IF (x mod 2) THEN ITERATE my_loop; ELSE SET str = CONCAT(str,x,','); END IF; END LOOP; SELECT str; END//

DELIMITER ;

call looper();

DELIMITER //

CREATE OR REPLACE PROCEDURE WhileLoop( iterations INT ) BEGIN DECLARE counter INT DEFAULT 1; WHILE counter = iterations DO select counter; SET counter = counter + 1; END WHILE; END//

DELIMITER ;

DELIMITER //

CREATE PROCEDURE RepeatDemo( iterations INT ) BEGIN DECLARE counter INT DEFAULT 1; DECLARE result VARCHAR(100) DEFAULT '';

REPEAT SET result = CONCAT(result,counter,','); SET counter = counter + 1; UNTIL counter = iterations END REPEAT;

SELECT result; END//

DELIMITER ;

DELIMITER //

CREATE PROCEDURE LeaveMe ( _id int ) sp: BEGIN DECLARE idCount INT DEFAULT 0;

-- check if the id exists SELECT COUNT(*) INTO idCount FROM app_user WHERE t_parent_id = _id;

IF idCount = 0 THEN LEAVE sp; END IF;

select * from app_user where t_parent_id = _id; END//

DELIMITER ;

Transcript Text
[Music]
[Music]
three two
one
well hello and welcome back we're
continuing our series of sequel
tutorials uh focused a lot on my sequel
maria db
and we're continuing at this point
looking at uh basically looking at store
procedures although
the
a lot of things that we're learning here
these syntax related items could be done
within queries as well
or
within just general scripts
they tend to be more useful though
or more prevalent at least in a stored
procedure concept
this time we're going to look at loops a
couple different looping mechanisms
so jumping into our little database here
the first thing i want to do and
actually
expand that out just a little bit so we
see it better
so this would be our first um
oh i've got an error somewhere in there
uh let's see
set counter
blah blah blah
oops i didn't declare that yet so i'm
going to jump over first i'm going to do
is we're going to look at loops but let
me
walk about this before i fix that uh
what we're going to see is got just a
little procedure i'm going to call it
while loop
and we're going to send it something
called iterations so it's just how many
times we're going to run it
and then we're going to have a counter
and then we're gonna basically just
count up say well the counter is less
than iterations do
and it's just gonna select counter
and then we're gonna set counter equals
counter
plus one
so
let's see let's see what we messed up
with here
so if we go in here
he is iterations he's going to clear
that
and counter equals counter plus one
should be right it's a while
so let's try that again let's see what
we missed here
okay so it looks like dang it i'm back
into this final thing so let's go back
to here we go so
source
uh
oh
let me go to current.com i do create
or replace
okay so now i've got my loop i'm sorry
so i've got my loop and what i'm going
to do is um
i'm able to what i'm going to do is i'm
just going to give it a number of
iterations this while loop thing
and it's going to be while the counter
is less iterations i'm just going to
select a number
add to it and then do my loop
and so if i do call while loop
with uh let's just do one
then i'm gonna see my counter if i do it
five times
then i can see here where it does a
counter at each of those i could also do
a counter at the end of it
and within this within our while loop
um what i do want to show
let's just do this real quick i'll paste
this even though it won't like it ah
here we go
there we'll blow that up a little bit
okay that'll be a little easier to read
so
and actually i'm here
three two
one on here let's do this let's just
bring the whole guy over
be a little easier to read
so while we're in here notice that it's
it doesn't have like a beginner and it's
sort of like an f is that you start with
your while
and then you've got
some commands
and then in while now in here we can do
all sorts of stuff we can do selects we
can do updates we can do whatever we
want this is just
your typical coding syntax structure
so we're in
a pretty good shape now to start doing
some loops if we wanted to
but as always
we may not want to do it as a while
but for example
i do want a good wild example would be
maybe you want to go through
and process
records in a table
and after each one
there may be
maybe there's records deleted or there's
values that are changed or at least each
cycle
and
you're going to want to basically
re-query it and just say while i still
have records in here to process then do
processing
and you easily see this a lot with um
some sort of transactional type data
where there's like let's say there's a
status that's
not processed
and what you could do is especially
depending on the
timing of the processing and stuff like
that
it may take a little while so it could
be that the
records to be processed have changed
since you cycle through
now depending on the size of the table
it could be costly to have something
where you're
regularly
checking uh you know going back and
hitting a
a bunch of records but what you could do
is have something where you start out
and you do like uh you know up here you
do something like select
records to be processed
if i can type that right
first you do like select records to be
processed
then you do your processing loop
and then
even within this you would have like
well
let's sit this way
wow
we have records
to process
so you grab them all or maybe some limit
of it you know like say select
next 10
or let's say next 100 records to be
processed
and then
you just keep on going through that and
then you know you'd have an n while down
here
of records to process
so basically what you could do is you
could say select the next 100
process them
and then come through and then select
the next 100 so as long as you have some
you're going to keep iterating through
it you can have a couple of you know
nested loops in that sense
let me get rid of those for posterity's
sake
and let me make sure in the
notes
that i have that
and then
oh that's not the one i want i want this
one
so that's our while loop now another one
we can do is a repeat loop
and that one looks like
this oops let me throw this in the
current real quick apologies while i'm
moving stuff around a little bit
because my copy and paste does not seem
to like itself right now so in this one
with repeat same thing i'm going to give
it a number of iterations it's going to
feel
basically the same i'm going to do
something a little different just to mix
it up though but i come in and i declare
my counter
and
i'm going to have a result which is a
string
so you know we don't want to get too
long but uh what it's done with each one
is it's going to count uh it's gonna
come in and it's gonna set the result
equal to
whatever our
number the result is plus the counter
and then a comma
so it'll be you know one comma two three
comma one comma two comma three comma
four comma five comma blah blah blah
update our counter and we're just gonna
repeat until the counter is greater than
or equal to the number of iterations
and then in repeat
and then we're at the end just going to
select the result we're just going to
print that out so it won't be quite as
complicated
to see
oh so if i just do
let's see if i got that right
okay so he's there i called him repeat
demo
so now if i do call repeat
demo
now let's say i do it and we'll do it
five times
so he comes through and he does one two
three four and then a comma and note
uh let's see so i start with one
and i'm going to repeat it until the
counter is greater than or equal to the
number of iterations well this case it's
actually
um
i probably wanted to start this at a
zero and change around a little bit
because i'm not getting five iterations
because i already started
at iteration one and so when i come
through here
he's checking it at two
so really what i'd wanna do is say
greater than the number of iterations
uh and let whoop
i don't wanna do that uh i don't want to
do create
or replace
and now if i do it oops i need to put
this in this current
and now if i do that
now let's see one two three four five
so you have to be as always you have to
be
cognizant and intentional about how you
do your your numbers and particularly
off by ones you know less than equal
greater than equal things like that
happen
regularly so you're going to want to see
where your counter
you know gets incremented and you would
run into this with while loops as well
it just happened to be this is a good
time to examine it
and one of the difference between
repeats and whiles is
a while does the check at the beginning
which means it may not even run at all
because you could say while true equals
false and it would just skip it because
true never equals false repeat until
always runs once at least
so if you did repeat until true equals
false
then
it will run it once and then it'll be
done
so that's something to consider as well
do you want it to run does your root
loop need to execute at least once
or not you know is it something that you
may not want to execute it at all
and so
let's look at
uh
let's see
oh wrong one let's look at our next one
which is going to be let's do a leave
now what you can do here let's bring
this over here so we can read it
we're going to add
labels
and this label here we're just going to
call it sp for stored procedure
and we're going to call this thing leave
me and it's just going to go through
it's got this id count
and what i'm going to do is i'm going to
see this is working with our tables
again so i'm going to say do i have
an id
for
an app user equal to whatever id i sent
in
so then if i do or i'm sorry
if i don't which means if i can't find
one here
and so let's look at that so if we do
it's like count star from there
and uh let's say i make the id equals
one
oh
uh i'm sorry it doesn't like that
because of the into
our
let's change this real quick
sorry so let's do count star let's get
rid of the n2
and do this and we'll just clean this up
a little bit
so we're normally going to see so let's
just say let's start with one
so if we come in here
i have one that's got an id of one do i
have one with an id of three yes i do do
i have one with an id of six no i do not
so i'm getting this count i have one id
and since this is a primary key
it's either one or zero that's what i'm
going to run into
so
for this
let me get rid of this
what i'm going to do is i'm going to see
do i have it
if id counts equals 0 which means if i
don't
then we're going to use this thing
called leave
and what leave does is it says basically
jump out
to leave this bracket
this labeled bracket in this case it's
going to be the store procedure itself
so
if they give me an id that's not valid
i'm not going to do anything otherwise
i'm going to select start from app user
i'm going to get that record
so if i take this uh see he should be
all good let's throw him into current
real quick
uh well let's do that i think that's
where he's at
where is current let's close a couple of
these like random files
okay so now
oh that one this one
and so we're gonna do our source current
there we go and what do we call this we
call this leave me
so if we call leave me
with one because we know the idea of one
exists
then we get that record if we do it with
two
then
two doesn't exist but three does i think
there you go three does
does four
four does does five
five does six does not we just check
that so six doesn't so you either get
the record or not
and so you can do
a lot of different things like this
to
basically bail out of a loop
which brings us to
just a general loop
uh
let's see where did i put oh here we go
so let's look at this general loop and i
may actually change this
okay
so whoop
so let's put this where you can read it
so very general loop
uh we're gonna call this one looper and
this one
is just gonna loop
and it's just account i'm not even
giving it i'm just gonna throw a number
out there
and so here i've got this loop label so
now the label is not on the stored
procedure but it's on the loop
and so what happens is what i'm going to
do is i'm going to say hey if x which is
this little number that i set to 1. it's
greater than 10 then i'm going to leave
and i'm going to leave it here which
means
this thing this structure
i'm going to leave it and i'm going to
come to the next line which is going to
be this select string
here i'm going to do set x i'm going to
increment my counter
if it equals
uh and basically
if it's even then i'm going to iterate
otherwise i'm going to concatenate a
string
and then i'm going to bail out so it's a
you know a different little
it's a different little way to approach
stuff
uh just as a simple
sample uh but let me do this actually
what i'm gonna do is let's just change
this up
a little bit
and instead of this what we want to do
is
let's do
so this one we're going to come in
and
we're just going to start building up
numbers but if we get beyond 10
then we're going to leave the loop
uh let's see
so let's go here let's go current
and let's make sure i've gotten that one
sort of updated because i tweaked that a
little bit
and now if i do current
okay so he's good and i called him
looper
which has no parameters so if i call it
i'm missing something here
oh i got rid of my x equals x plus one
so
that's a problem
oh i lost like a bunch of that i did not
copy that over properly
oh there that's the whole thing okay
let me show axe oh
i managed to
totally screwed
that one
up
let's do create or replace
just to be simple instead of doing a
drop
and we're going to go over here and
we'll do the same thing create
or
replace
um
oh and i just need to run it again
so
uh
see
what i miss here
oh i'm sorry and i can iterate on
my loop this is to give me a little go
to i'm sorry i missed this one too
um
we have leave
i can jump out of my loop but iterate is
just going to jump me back to
the top of the loop again so it's like a
go to
let me just see this let me throw this
over here just make sure we're good with
it i don't lose it
and so let's jump back over here we can
see a little better i'm sorry i missed
this part
so in here
is i have this iterate and so here i'm
going to come through and i can leave it
which means go to the next one or i can
iterate it which basically says go to
that label
and so if i do that
let's see if i do current
and now execute it
then
it's going to come through and it prints
my even numbers as i expected
so i think that's we're going to wrap
this one up because we've we've covered
a couple little things with our looping
mechanisms we will return we'll see some
a little bit more use of
labels and ways to sort of pop around a
little bit
and we've got some other structures
within stored procedures that we can use
to
wheel and deal with our data
that being said
that wraps this one up so go out there
and have yourself a great day
a great week and we will talk to you
next time
you
Transcript Segments
0.43

[Music]

27.25

[Music]

29.119

three two

30.96

one

31.84

well hello and welcome back we're

33.52

continuing our series of sequel

36.16

tutorials uh focused a lot on my sequel

38.879

maria db

40.16

and we're continuing at this point

41.92

looking at uh basically looking at store

44.32

procedures although

46.32

the

47.68

a lot of things that we're learning here

48.96

these syntax related items could be done

51.28

within queries as well

53.68

or

54.48

within just general scripts

57.44

they tend to be more useful though

59.84

or more prevalent at least in a stored

62.239

procedure concept

64.239

this time we're going to look at loops a

67.28

couple different looping mechanisms

70.24

so jumping into our little database here

72.4

the first thing i want to do and

74.479

actually

75.28

expand that out just a little bit so we

76.88

see it better

79.119

so this would be our first um

81.52

oh i've got an error somewhere in there

86.24

uh let's see

89.28

set counter

90.72

blah blah blah

92.72

oops i didn't declare that yet so i'm

95.68

going to jump over first i'm going to do

96.96

is we're going to look at loops but let

97.92

me

98.72

walk about this before i fix that uh

100.96

what we're going to see is got just a

103.52

little procedure i'm going to call it

104.88

while loop

106.799

and we're going to send it something

108.479

called iterations so it's just how many

110.24

times we're going to run it

112.079

and then we're going to have a counter

114.64

and then we're gonna basically just

116.719

count up say well the counter is less

118.399

than iterations do

120.479

and it's just gonna select counter

123.04

and then we're gonna set counter equals

124.719

counter

125.68

plus one

129.2

so

134.08

let's see let's see what we messed up

135.84

with here

138

so if we go in here

141.28

he is iterations he's going to clear

143.52

that

149.52

and counter equals counter plus one

152.239

should be right it's a while

158.48

so let's try that again let's see what

160.319

we missed here

162.319

okay so it looks like dang it i'm back

164.72

into this final thing so let's go back

166.959

to here we go so

168.879

source

170.64

uh

171.599

oh

175.12

let me go to current.com i do create

178.56

or replace

185.12

okay so now i've got my loop i'm sorry

188.4

so i've got my loop and what i'm going

189.44

to do is um

194.4

i'm able to what i'm going to do is i'm

196

just going to give it a number of

196.879

iterations this while loop thing

200.64

and it's going to be while the counter

202.08

is less iterations i'm just going to

203.519

select a number

204.959

add to it and then do my loop

207.2

and so if i do call while loop

212.159

with uh let's just do one

215.44

then i'm gonna see my counter if i do it

218

five times

220.319

then i can see here where it does a

222.239

counter at each of those i could also do

224.56

a counter at the end of it

226.879

and within this within our while loop

229.599

um what i do want to show

233.04

let's just do this real quick i'll paste

234.56

this even though it won't like it ah

237.2

here we go

239.68

there we'll blow that up a little bit

241.12

okay that'll be a little easier to read

242.799

so

244.319

and actually i'm here

264

three two

265.759

one on here let's do this let's just

268.4

bring the whole guy over

271.12

be a little easier to read

273.52

so while we're in here notice that it's

275.6

it doesn't have like a beginner and it's

277.199

sort of like an f is that you start with

278.72

your while

280

and then you've got

281.84

some commands

283.84

and then in while now in here we can do

286.8

all sorts of stuff we can do selects we

289.199

can do updates we can do whatever we

291.28

want this is just

293.12

your typical coding syntax structure

297.199

so we're in

298.479

a pretty good shape now to start doing

300.88

some loops if we wanted to

302.639

but as always

304.08

we may not want to do it as a while

307.68

but for example

309.199

i do want a good wild example would be

311.6

maybe you want to go through

313.759

and process

315.84

records in a table

318.08

and after each one

320.08

there may be

321.199

maybe there's records deleted or there's

323.039

values that are changed or at least each

325.44

cycle

326.88

and

328.08

you're going to want to basically

329.199

re-query it and just say while i still

330.8

have records in here to process then do

333.12

processing

334.8

and you easily see this a lot with um

338.16

some sort of transactional type data

340.56

where there's like let's say there's a

341.84

status that's

343.199

not processed

344.8

and what you could do is especially

346.88

depending on the

348.16

timing of the processing and stuff like

350.08

that

351.36

it may take a little while so it could

352.639

be that the

354.479

records to be processed have changed

356.72

since you cycle through

359.039

now depending on the size of the table

360.24

it could be costly to have something

361.919

where you're

363.36

regularly

364.479

checking uh you know going back and

366.16

hitting a

367.199

a bunch of records but what you could do

369.52

is have something where you start out

370.8

and you do like uh you know up here you

372.4

do something like select

375.12

records to be processed

377.84

if i can type that right

381.919

first you do like select records to be

383.52

processed

385.12

then you do your processing loop

388.56

and then

389.6

even within this you would have like

391.199

well

392.639

let's sit this way

394.4

wow

395.28

we have records

397.039

to process

399.199

so you grab them all or maybe some limit

401.28

of it you know like say select

403.6

next 10

406.16

or let's say next 100 records to be

408.319

processed

411.759

and then

412.8

you just keep on going through that and

414.16

then you know you'd have an n while down

415.84

here

418.8

of records to process

421.12

so basically what you could do is you

422.319

could say select the next 100

424.56

process them

426.72

and then come through and then select

427.919

the next 100 so as long as you have some

430.24

you're going to keep iterating through

431.68

it you can have a couple of you know

432.96

nested loops in that sense

435.28

let me get rid of those for posterity's

437.759

sake

441.84

and let me make sure in the

444.639

notes

446.8

that i have that

449.12

and then

452.08

oh that's not the one i want i want this

454.96

one

458.72

so that's our while loop now another one

460.319

we can do is a repeat loop

465.919

and that one looks like

468.16

this oops let me throw this in the

469.44

current real quick apologies while i'm

471.199

moving stuff around a little bit

473.36

because my copy and paste does not seem

474.72

to like itself right now so in this one

476.8

with repeat same thing i'm going to give

478.8

it a number of iterations it's going to

481.039

feel

482

basically the same i'm going to do

483.44

something a little different just to mix

484.879

it up though but i come in and i declare

487.039

my counter

489.36

and

490.479

i'm going to have a result which is a

492

string

493.12

so you know we don't want to get too

494.639

long but uh what it's done with each one

497.199

is it's going to count uh it's gonna

499.599

come in and it's gonna set the result

501.199

equal to

502.319

whatever our

503.68

number the result is plus the counter

506.72

and then a comma

508.24

so it'll be you know one comma two three

509.84

comma one comma two comma three comma

511.759

four comma five comma blah blah blah

514

update our counter and we're just gonna

515.76

repeat until the counter is greater than

517.519

or equal to the number of iterations

519.599

and then in repeat

521.519

and then we're at the end just going to

522.719

select the result we're just going to

523.919

print that out so it won't be quite as

526.56

complicated

528.48

to see

530.48

oh so if i just do

532.08

let's see if i got that right

535.12

okay so he's there i called him repeat

537.6

demo

538.64

so now if i do call repeat

541.76

demo

543.36

now let's say i do it and we'll do it

544.88

five times

548.48

so he comes through and he does one two

549.92

three four and then a comma and note

553.68

uh let's see so i start with one

556.72

and i'm going to repeat it until the

558.72

counter is greater than or equal to the

560.16

number of iterations well this case it's

562.64

actually

564.24

um

565.36

i probably wanted to start this at a

567.2

zero and change around a little bit

568.8

because i'm not getting five iterations

572.24

because i already started

574

at iteration one and so when i come

576.72

through here

577.839

he's checking it at two

580.72

so really what i'd wanna do is say

583.12

greater than the number of iterations

586.399

uh and let whoop

588.24

i don't wanna do that uh i don't want to

590.64

do create

592.24

or replace

594.72

and now if i do it oops i need to put

597.04

this in this current

600.8

and now if i do that

605.44

now let's see one two three four five

609.04

so you have to be as always you have to

611.44

be

612.64

cognizant and intentional about how you

614.8

do your your numbers and particularly

617.279

off by ones you know less than equal

619.279

greater than equal things like that

620.56

happen

621.44

regularly so you're going to want to see

623.04

where your counter

624.72

you know gets incremented and you would

626.56

run into this with while loops as well

628.8

it just happened to be this is a good

630.48

time to examine it

632.72

and one of the difference between

633.68

repeats and whiles is

636.079

a while does the check at the beginning

638.32

which means it may not even run at all

641.36

because you could say while true equals

643.04

false and it would just skip it because

645.04

true never equals false repeat until

648.24

always runs once at least

650.8

so if you did repeat until true equals

653.04

false

654.16

then

655.12

it will run it once and then it'll be

657.519

done

659.12

so that's something to consider as well

660.56

do you want it to run does your root

662.399

loop need to execute at least once

665.76

or not you know is it something that you

667.44

may not want to execute it at all

670.88

and so

672.88

let's look at

677.519

uh

678.88

let's see

679.92

oh wrong one let's look at our next one

682.16

which is going to be let's do a leave

685.92

now what you can do here let's bring

688.56

this over here so we can read it

690.64

we're going to add

693.44

labels

695.12

and this label here we're just going to

697.04

call it sp for stored procedure

699.839

and we're going to call this thing leave

701.2

me and it's just going to go through

702.88

it's got this id count

705.44

and what i'm going to do is i'm going to

707.04

see this is working with our tables

708.48

again so i'm going to say do i have

711.2

an id

712.959

for

713.76

an app user equal to whatever id i sent

716.24

in

716.959

so then if i do or i'm sorry

719.519

if i don't which means if i can't find

721.92

one here

724.24

and so let's look at that so if we do

725.6

it's like count star from there

728.839

and uh let's say i make the id equals

731.92

one

734.079

oh

735.04

uh i'm sorry it doesn't like that

737.04

because of the into

739.519

our

740.56

let's change this real quick

742.839

sorry so let's do count star let's get

745.76

rid of the n2

753.279

and do this and we'll just clean this up

756.16

a little bit

757.76

so we're normally going to see so let's

759.6

just say let's start with one

763.519

so if we come in here

766.32

i have one that's got an id of one do i

768.24

have one with an id of three yes i do do

770.48

i have one with an id of six no i do not

772.88

so i'm getting this count i have one id

775.12

and since this is a primary key

776.88

it's either one or zero that's what i'm

778.639

going to run into

780.399

so

782.079

for this

783.2

let me get rid of this

784.72

what i'm going to do is i'm going to see

786

do i have it

787.279

if id counts equals 0 which means if i

789.839

don't

790.72

then we're going to use this thing

791.76

called leave

793.279

and what leave does is it says basically

795.6

jump out

796.959

to leave this bracket

799.2

this labeled bracket in this case it's

800.8

going to be the store procedure itself

802.32

so

803.519

if they give me an id that's not valid

805.519

i'm not going to do anything otherwise

807.6

i'm going to select start from app user

809.6

i'm going to get that record

811.92

so if i take this uh see he should be

815.2

all good let's throw him into current

816.72

real quick

818.88

uh well let's do that i think that's

820.639

where he's at

822.48

where is current let's close a couple of

824.48

these like random files

831.279

okay so now

832.88

oh that one this one

836.959

and so we're gonna do our source current

838.959

there we go and what do we call this we

841.12

call this leave me

842.56

so if we call leave me

844.56

with one because we know the idea of one

846.639

exists

847.76

then we get that record if we do it with

849.839

two

851.76

then

853.279

two doesn't exist but three does i think

855.839

there you go three does

857.68

does four

858.88

four does does five

860.8

five does six does not we just check

862.959

that so six doesn't so you either get

864.88

the record or not

867.12

and so you can do

870.399

a lot of different things like this

873.92

to

874.88

basically bail out of a loop

878

which brings us to

880.639

just a general loop

882.639

uh

884.88

let's see where did i put oh here we go

888.399

so let's look at this general loop and i

890

may actually change this

892.24

okay

893.44

so whoop

894.959

so let's put this where you can read it

897.12

so very general loop

898.8

uh we're gonna call this one looper and

901.12

this one

903.199

is just gonna loop

904.72

and it's just account i'm not even

905.839

giving it i'm just gonna throw a number

907.199

out there

908.959

and so here i've got this loop label so

911.199

now the label is not on the stored

912.639

procedure but it's on the loop

915.04

and so what happens is what i'm going to

916.959

do is i'm going to say hey if x which is

919.6

this little number that i set to 1. it's

921.199

greater than 10 then i'm going to leave

922.72

and i'm going to leave it here which

924.839

means

926.56

this thing this structure

929.519

i'm going to leave it and i'm going to

930.8

come to the next line which is going to

932.079

be this select string

934.24

here i'm going to do set x i'm going to

936.399

increment my counter

938.16

if it equals

940.56

uh and basically

943.12

if it's even then i'm going to iterate

945.519

otherwise i'm going to concatenate a

947.519

string

948.56

and then i'm going to bail out so it's a

950.72

you know a different little

954.88

it's a different little way to approach

956.32

stuff

957.92

uh just as a simple

959.68

sample uh but let me do this actually

963.12

what i'm gonna do is let's just change

965.519

this up

967.12

a little bit

968.88

and instead of this what we want to do

972

is

976.32

let's do

981.199

so this one we're going to come in

983.36

and

985.36

we're just going to start building up

986.48

numbers but if we get beyond 10

988.8

then we're going to leave the loop

992.32

uh let's see

994.24

so let's go here let's go current

1000.399

and let's make sure i've gotten that one

1002.639

sort of updated because i tweaked that a

1004.48

little bit

1007.36

and now if i do current

1009.839

okay so he's good and i called him

1013.36

looper

1015.6

which has no parameters so if i call it

1020.079

i'm missing something here

1022.639

oh i got rid of my x equals x plus one

1025.199

so

1026.559

that's a problem

1031.28

oh i lost like a bunch of that i did not

1033.679

copy that over properly

1040.16

oh there that's the whole thing okay

1044.64

let me show axe oh

1046.88

i managed to

1054.24

totally screwed

1056.4

that one

1058.08

up

1060.32

let's do create or replace

1063.12

just to be simple instead of doing a

1065.28

drop

1067.76

and we're going to go over here and

1069.2

we'll do the same thing create

1072

or

1073.36

replace

1076.96

um

1078.4

oh and i just need to run it again

1081.84

so

1082.799

uh

1083.679

see

1087.28

what i miss here

1092.84

oh i'm sorry and i can iterate on

1096.559

my loop this is to give me a little go

1098.48

to i'm sorry i missed this one too

1100.96

um

1103.36

we have leave

1104.88

i can jump out of my loop but iterate is

1106.88

just going to jump me back to

1109.12

the top of the loop again so it's like a

1110.88

go to

1113.44

let me just see this let me throw this

1115.52

over here just make sure we're good with

1117.039

it i don't lose it

1121.44

and so let's jump back over here we can

1123.36

see a little better i'm sorry i missed

1124.72

this part

1126.88

so in here

1130

is i have this iterate and so here i'm

1132.4

going to come through and i can leave it

1134.48

which means go to the next one or i can

1136.4

iterate it which basically says go to

1139.36

that label

1141.52

and so if i do that

1143.28

let's see if i do current

1145.919

and now execute it

1147.919

then

1148.88

it's going to come through and it prints

1150.4

my even numbers as i expected

1154.88

so i think that's we're going to wrap

1156.08

this one up because we've we've covered

1158.32

a couple little things with our looping

1159.679

mechanisms we will return we'll see some

1161.6

a little bit more use of

1163.679

labels and ways to sort of pop around a

1166.48

little bit

1168.16

and we've got some other structures

1170.08

within stored procedures that we can use

1172

to

1173.36

wheel and deal with our data

1175.52

that being said

1176.72

that wraps this one up so go out there

1178.72

and have yourself a great day

1180.48

a great week and we will talk to you

1183.76

next time

1200.72

you