title: ZipCode Query to pull Five and Nine Digits
body: <p>I am trying to pull a query in MSSQL to pull the if they exist 9 digits zipcodes out of the cus_address table. I am already pulling 5 digit zipcodes out of a table i created myself called dbo.WEST_PALM_ZIPS. I need to pull all the zips in my WEST_PALM_ZIPS table as well as the CUS_ADDRESS.POSTAL_CODE (any help is appreciated)</p>
  
  <pre><code>SELECT DISTINCT [Member Id] = Cust.MASTER_CUSTOMER_ID,[FirstName] = Cust.First_Name    
  
  [Lastname] = Cust.Last_Name,
  
  [Email] = Cust.PRIMARY_EMAIL_ADDRESS,
  
  [Zip Code] = addr.POSTAL_CODE
  
  FROM ORDER_DETAIL OD
  INNER JOIN CUSTOMER  Cust 
      ON  Cust.MASTER_CUSTOMER_ID = OD.SHIP_MASTER_CUSTOMER_ID 
      and Cust.SUB_CUSTOMER_ID = OD.SHIP_SUB_CUSTOMER_ID 
      and od.subsystem = 'MBR'
  
  INNER JOIN CUS_ADDRESS  Addr    
      ON Addr.CUS_ADDRESS_ID = OD.SHIP_ADDRESS_ID  
      and Addr.POSTAL_CODE in ( select POSTAL_CODE from [dbo].[WEST_PALM_ZIPS])
      and Addr.COUNTRY_descr = 'United States'
      and  If(Len([Postal_Code])&gt;5,Left([Postal_Code],5) &amp; "-" &amp;
  Mid([Postal_Code],6),[Postal_Code])][0-9]
  
  
  INNER JOIN CUS_ADDRESS_DETAIL  AddrD 
      ON AddrD.MASTER_CUSTOMER_ID = OD.SHIP_MASTER_CUSTOMER_ID 
      and AddrD.SUB_CUSTOMER_ID = OD.SHIP_SUB_CUSTOMER_ID 
      and AddrD.CUS_ADDRESS_ID = OD.SHIP_ADDRESS_ID 
      and AddrD.ADDRESS_TYPE_CODE = OD.SHIP_ADDRESS_TYPE_CODE     
  </code></pre>