SHARE
TWEET

Untitled

a guest Jul 12th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. DECLARE @startnum INT=1000
  2. DECLARE @endnum INT=1004
  3. ;
  4. WITH gen AS (
  5.     SELECT @startnum AS num
  6.     UNION ALL
  7.     SELECT num+1 FROM gen WHERE num+1<=@endnum
  8. )
  9. SELECT * FROM gen
  10. option (maxrecursion 0)
  11.      
  12. select a1.*, a2.*
  13. from
  14. (select
  15.       1000 as v1
  16. union all
  17. select
  18.       1001 as v1
  19. union all
  20. select
  21.       1003 as v1)a1
  22. left join
  23. (select
  24.       1000 as v2
  25. union all
  26. select
  27.       1001 as v2
  28. union all
  29. select
  30.       1003 as v2
  31. union all
  32. select
  33.       1004 as v2)a2
  34.     ON a1.v1=a2.v2
  35.      
  36. DECLARE @startnum INT=1000
  37. DECLARE @endnum INT=1004
  38. ;
  39. WITH gen AS (
  40.     SELECT @startnum AS num
  41.     UNION ALL
  42.     SELECT num+1 FROM gen WHERE num+1<=@endnum
  43. ),cte as
  44. (
  45. SELECT * FROM gen
  46.  
  47. ) , cte1 as
  48. (
  49. select a1.* from
  50. (select
  51.       1000 as v1
  52. union all
  53. select
  54.       1001 as v1
  55. union all
  56. select
  57.       1003 as v1
  58.       )a1
  59.  
  60. ) select cte.*,cte1.* from cte join cte1 on cte.num=cte1.v1
  61.      
  62. WITH gen AS (
  63.       SELECT @startnum AS num
  64.       UNION ALL
  65.       SELECT num + 1
  66.       FROM gen
  67.       WHERE num + 1 <= @endnum
  68.      )
  69. SELECT
  70. FROM gen JOIN
  71.      a1
  72.      ON a1.v1 = gen.num
  73. OPTION (MAXRECURSION 0);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top