胡说叔叔
属性选择非持久化值。VALUES关键词。然后使用JOIN生成大量和大量的组合(可以扩展到创建数十万行和更多行)。SELECT ones.n + 10*tens.n + 100*hundreds.n + 1000*thousands.nFROM (VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) ones(n),
(VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) tens(n),
(VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) hundreds(n),
(VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) thousands(n)
WHERE ones.n + 10*tens.n + 100*hundreds.n + 1000*thousands.n BETWEEN @userinput1 AND @userinput2ORDER BY 1演示一种较短的备选办法,这并不容易理解:WITH x AS (SELECT n FROM (VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) v(n))
SELECT ones.n + 10*tens.n + 100*hundreds.n + 1000*thousands.nFROM x ones,
x tens,
x hundreds,
x thousandsORDER BY 1演示