SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SELECT DISTINCT table1.status AS Status
  2. FROM table1
  3. INNER JOIN (
  4.         SELECT DataID, MAX(VersionNum) as mVersion
  5.         FROM table1
  6.         GROUP BY DataID
  7.     ) AS b
  8.     ON table1.DataID = b.DataID
  9.     AND table1.VersionNum = b.mVersion
  10. INNER JOIN table2
  11.     ON table1.table2ID = table2.ID
  12. WHERE table2.field = @parameter
  13.    
  14. WITH CTE_Versions AS (
  15.       SELECT DataID, MAX(VersionNum) as mVersion
  16.       FROM t1
  17.       GROUP BY DataID
  18.   )
  19.   SELECT DISTINCT t1.status AS Status
  20.   FROM t1
  21.   JOIN CTE_Versions AS b
  22.       ON t1.DataID = b.DataID
  23.       AND t1.VersionNum = b.mVersion
  24.   JOIN table2
  25.       ON t1.table2ID = table2.ID
  26.   WHERE table2.field = @parameter
  27.    
  28. SELECT DISTINCT t1.status AS Status
  29.   FROM t1 with (nolock)
  30.   JOIN (
  31.           SELECT DataID, MAX(VersionNum) as mVersion
  32.           FROM t1 with (nolock)
  33.           GROUP BY DataID
  34.   ) AS b
  35.       ON t1.DataID = b.DataID
  36.       AND t1.VersionNum = b.mVersion
  37.   JOIN table2 with (nolock)
  38.       ON t1.table2ID = table2.ID
  39.   WHERE table2.field = @parameter
  40.    
  41. SELECT DISTINCT t1.status AS Status
  42.   FROM t1
  43.   JOIN (
  44.           SELECT DataID, MAX(VersionNum) as mVersion
  45.           FROM t1
  46.           GROUP BY DataID
  47.   ) AS b
  48.       ON  t1.DataID = b.DataID
  49.       AND t1.VersionNum = b.mVersion
  50.   JOIN table2
  51.       ON  t1.table2ID = table2.ID
  52.       AND table2.field = @parameter
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