clear markdown compare help best fiddles feedback dbanow.uk a leap of faith?
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 1130760 fiddles created (16571 in the last week).

CREATE OR ALTER FUNCTION dbo.EXPENSIVE_UDF () RETURNS INT AS BEGIN DECLARE @tbl TABLE (VAL VARCHAR(5)); INSERT INTO @tbl SELECT [VALUE] FROM STRING_SPLIT(REPLICATE(CAST('Z ' AS VARCHAR(MAX)), 20000), ' '); RETURN 1; END;
 hidden batch(es)


DROP TABLE IF EXISTS dbo.X_100_INTEGERS; CREATE TABLE dbo.X_100_INTEGERS (ID INT NOT NULL); -- insert 100 integers from 1 - 100 WITH L0 AS(SELECT 1 AS c UNION ALL SELECT 1), L1 AS(SELECT 1 AS c FROM L0 AS A CROSS JOIN L0 AS B), L2 AS(SELECT 1 AS c FROM L1 AS A CROSS JOIN L1 AS B), L3 AS(SELECT 1 AS c FROM L2 AS A CROSS JOIN L2 AS B), L4 AS(SELECT 1 AS c FROM L3 AS A CROSS JOIN L3 AS B), L5 AS(SELECT 1 AS c FROM L4 AS A CROSS JOIN L4 AS B), Nums AS(SELECT ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) AS n FROM L5) INSERT INTO dbo.X_100_INTEGERS WITH (TABLOCK) SELECT n FROM Nums WHERE n <= 100;
100 rows affected
 hidden batch(es)


SET STATISTICS TIME ON; SELECT x1.ID FROM dbo.X_100_INTEGERS x1 WHERE x1.ID >= dbo.EXPENSIVE_UDF();
ID
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
SQL Server Execution Times: CPU time = 16922 ms, elapsed time = 17265 ms.
 hidden batch(es)