So I had a problem where one of the companies we work with wanted data for a column, however they wanted a single example. However in our system we can have multiple entries for that column. I needed to get a single example other wise when joining would show other many more rows than necessary for what they wanted. SO I turned to Common Table Expressions (CTE)s. Although turned out that because I was excluding data one of my bosses said just not to send that field, because it would be similar to misinformation. Hah. ;With PBs(accountID,PBName,rn) AS ( select ACV.accountID, B.lastName + ', ' + B.firstName + ' ' + B.middleInit, ROW_NUMBER() OVER (PARTITION BY acv.accountID ORDER BY acv.accountID DESC) as rn FROM ACV --- etc joins where --conditions group by ACV.accountID, B.lastName + ', ' + B.firstName + ' ' + B.middleInit ) SELECT --other fields PB.PBName FROM ACV ---joins LEFT OUTER JOIN PBs...
Comments
Post a Comment