Created
August 8, 2012 15:16
-
-
Save swasheck/3295822 to your computer and use it in GitHub Desktop.
View Query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT distinct | |
tbl1.col1 [Document ID], | |
tbl2.col2 [Description], | |
tbl1.col3 [Revision], | |
tbl1.col4 [Effective Date], | |
tbl4.col5 [Part#], | |
tbl5.col2 [Part Description] | |
FROM DB.dbo.table1 tbl1 | |
INNER JOIN DB.dbo.table2 tbl2 | |
ON tbl1.col1 = tbl2.col1 | |
LEFT OUTER JOIN DDB.dbo.table3 tbl3 | |
ON tbl1.col6 = tbl3.col6 | |
LEFT OUTER JOIN DB.dbo.table4 tbl4 ON tbl1.col1 = tbl4.t_sitm | |
LEFT OUTER JOIN DB.dbo.table5 tbl5 | |
ON tbl4.col5 = tbl5.col5 | |
LEFT OUTER JOIN ( | |
SELECT col1, MAX(col4) col4 | |
FROM DB.dbo.table1 | |
GROUP BY col1 | |
) tbl1 _2 ON tbl1.col1 = tbl1 _2.col1 | |
WHERE ((RIGHT(LTRIM(RTRIM(tbl1.col1)), 3) = '-30') OR | |
(RIGHT(LTRIM(RTRIM(tbl1.col1)), 3) = '-35') OR | |
(RIGHT(LTRIM(RTRIM(tbl1.col1)), 3) = '-02') | |
OR | |
(LEFT(LTRIM(RTRIM(tbl1.col1)), 1) = 'N')) | |
AND tbl1.col7 = 1 | |
AND tbl3.col8 >= '2007-01-01' | |
AND ((tbl5.col9 = 1) OR | |
(tbl5.col5 IS NULL)) | |
AND LTRIM(RTRIM(tbl1.col3)) != '99' | |
AND LTRIM(RTRIM(tbl1.col3)) != '999' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment