#temp_1 returns 50,000 with probably 3000 unique part numbers.
Now i need to make another temp table from our pricing table that has MILLIONS of parts with many different change dates.
I want temp_2 to only insert the parts that were in #Temp_1. I tried this. . . but i still get all rows from ZATS
select * into #TEMP_1 FROM --this returns the correct data)
SELECT DISTINCT h.Customs_Entry_Num
,CAST(l.Entry_Line_ID AS INT) AS Entry_Line_ID
,CAST(l.entry_date AS DATE) AS [Entry_Date]
FROM ADHOC.ATS_ESH h
INNER JOIN ADHOC.ATS_ESL l
ON h.TRANS_SK = l.TRANS_SK
WHERE h.Importer = 'FORD'
AND h.Entry_Date > (GETDATE() - 40)
AND l.HTS_Num NOT LIKE '98%'
AND l.Part_Num <> 'NPN'
AND h.Com_Desc_Code = 'Parts'
AND SUBSTRING(l.Part_Num, 4, 1) <> 'Z'
) as ENTRY
select * into #TEMP_2 FROM
z.COMPOSITE_PART ----this is a column from pricing i want
,dateadd(d, 0, datediff(d, 0, CREATED_DATE)) As DateOnly --this is the change date
,z.HTS_NUMBER --treat this a the price
FROM TSI.ZATS_BROKER_FEED z
Left Join #TEMP_1
ON #TEMP_1.PART_NUM = Z.COMPOSITE_PART
WHERE Z.SUB_ORG = 'FORD'
) as ZATS