Skip to content

Instantly share code, notes, and snippets.

/demo.sql Secret

Created December 22, 2016 06:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/e74858c05d1ba97b11bb561437c45542 to your computer and use it in GitHub Desktop.
Save anonymous/e74858c05d1ba97b11bb561437c45542 to your computer and use it in GitHub Desktop.
create function dbo.GetRows(@ID int)
returns @T table
(
ID int,
D datetime
) with schemabinding as
begin
declare @N int;
-- Time passes
with C as
(
select 1 as N
union all
select C.N + 1
from C
where C.N < 50000
)
select @N = count(*)
from C
option (maxrecursion 0);
insert into @T(ID, D) values(@ID, getdate());
return;
end;
go
select R.ID, R.D
from (values(1),(1),(2),(2)) as T(ID)
cross apply dbo.GetRows(T.ID) as R
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment