public
Created

View Query

  • Download Gist
gistfile1.sql
SQL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
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'

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.