-
Notifications
You must be signed in to change notification settings - Fork 0
/
cross-apply.sql
47 lines (37 loc) · 868 Bytes
/
cross-apply.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
create function number_sequence(
@start_ integer,
@end_ integer,
@step_ integer = 1
)
returns @seq table(num integer)
as begin
declare @num integer = @start_;
while @num <= @end_ begin
insert into @seq values (@num);
set @num = @num + @step_;
end;
return;
end;
go
create function num_times_string(
@num integer,
@string varchar(10)
)
returns @ret table (string varchar(max))
as begin
declare @cnt integer = 1;
declare @str varchar(max) = '';
while @cnt <= @num begin
set @str = @str + @string;
insert into @ret values (@str);
set @cnt = @cnt + 1;
end;
return;
end;
go
select
*
from
number_sequence (2, 8, 3) s cross apply -- cross join -- The multi-part identifier "s.num" could not be bound.
num_times_string(s.num, '*')
;