Skip to content

Instantly share code, notes, and snippets.

@mgrigajtis
Last active April 6, 2017 12:41
Show Gist options
  • Save mgrigajtis/ed997b08c5d2cd9f7c44b89050bd52f5 to your computer and use it in GitHub Desktop.
Save mgrigajtis/ed997b08c5d2cd9f7c44b89050bd52f5 to your computer and use it in GitHub Desktop.
Worst Join So Far
#tmpResults t WITH (NOLOCK)
INNER JOIN table1 t1 WITH (NOLOCK)
ON t1.ALT_ID_WHO = 'M 17 ' + t.ALT_KEY
INNER JOIN table2 t2 WITH (NOLOCK)
ON SUBSTRING(t1.ALT_REF_ID,3,11) = t2.MemberNumber
AND CAST(CAST(t2.numericbeginningdate AS CHAR(8)) AS DATE) <= t.StartingDate
AND CAST(CAST(t2.numericendingdate AS CHAR(8)) AS DATE) >= t.StartingDate
AND t2.VOID <> 'V'
@mgrigajtis
Copy link
Author

Make sure you structure your data properly, otherwise you have to figure out joins that look like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment