我试图在 MSSQL 中提取一个查询,以从 cus_address 表中提取它们是否存在 9 位邮政编码。我已经从我自己创建的名为 dbo.WEST_PALM_ZIPS 的表中提取了 5 位数的邮政编码。我需要拉出我的 WEST_PALM_ZIPS 表以及 CUS_ADDRESS.POSTAL_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])>5,Left([Postal_Code],5) & "-" &
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