;WITH CTE_NONULLS AS ( SELECT MAX(CabinetID) AS CabinetID, TIN FROM [Trades].[dbo].[vw_CabinetNG_New] WHERE (Source = 'DST' OR Source = 'DAZL') AND (Address1 IS NOT NULL) AND (TIN IS NOT NULL AND TIN <> '000-00-0000') GROUP BY TIN), CTE_NULLS AS ( SELECT MAX(CabinetID) AS CABINETID, FirstName, TIN FROM [Trades].[dbo].[vw_CabinetNG_New] WHERE (Source = 'DST' OR Source = 'DAZL') AND (Address1 IS NOT NULL) AND ((FIRSTNAME IS NOT NULL AND FIRSTNAME <> '') OR (LASTNAME IS NOT NULL AND LASTNAME <> '')) AND (TIN IS NULL OR TIN = '000-00-0000') GROUP BY FirstName, TIN), CTE_FC AS ( SELECT TIN FROM [dbo].[vw_CabinetNG_New] WHERE Source = 'FirstClearing' GROUP BY TIN ) SELECT TIN , CASE WHEN [FirstName] IS NOT NULL THEN [FirstName] + ' ' ELSE '' END + CASE WHEN [LastName] IS NOT NULL THEN [LastName] ELSE '' END AS [Full Name] ,CASE WHEN [AdditionalName] IS NULL THEN '' ELSE [AdditionalName] END AS [AdditionalName] ,CASE WHEN [Address1] IS NULL THEN '' ELSE [Address1] END AS [Address1] ,CASE WHEN [Address2] IS NULL THEN '' ELSE [Address2] END AS [Address2] ,CASE WHEN [Address3] IS NULL THEN '' ELSE [Address3] END AS [Address3] ,[City] ,[State] ,[ZipCode] ,LastUpdated ,[Source] FROM [Trades].[dbo].[vw_CabinetNG_New] WHERE CabinetID IN (SELECT CabinetID FROM CTE_NONULLS UNION ALL SELECT CabinetID FROM CTE_NULLS) AND TIN NOT IN (SELECT TIN FROM CTE_FC) ORDER BY TIN
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE