SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


CREATING A 2ND TEMP TABLE BASED ON THE CONTENTS OF 1ST TEMP TABLE`


CREATING A 2ND TEMP TABLE BASED ON THE CONTENTS OF 1ST TEMP TABLE`

Author
Message
jeffshelix
jeffshelix
SSC Eights!
SSC Eights! (939 reputation)SSC Eights! (939 reputation)SSC Eights! (939 reputation)SSC Eights! (939 reputation)SSC Eights! (939 reputation)SSC Eights! (939 reputation)SSC Eights! (939 reputation)SSC Eights! (939 reputation)

Group: General Forum Members
Points: 939 Visits: 201
#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
thanks
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
,h.Broker_Invoice
,h.Entry_Type
,l.Part_Num
,l.HTS_Num
,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
(
SELECT DISTINCT
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

Alan Burstein
Alan Burstein
SSC Guru
SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)

Group: General Forum Members
Points: 50287 Visits: 8861
Can you post some DDL for the tables that you are pulling data from (Note the link in my signature line for best practices on getting help)

-- Alan Burstein


Helpful links:

Best practices for getting help on SQLServerCentral -- Jeff Moden
How to Post Performance Problems -- Gail Shaw

Nasty fast set-based string manipulation functions:
For splitting strings try DelimitedSplit8K or DelimitedSplit8K_LEAD (SQL Server 2012+)
To split strings based on patterns try PatternSplitCM
Need to clean or transform a string? try NGrams, PatExclude8K, PatReplace8K, DigitsOnlyEE, or Translate8K

I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code. -- Itzik Ben-Gan 2001

ZZartin
ZZartin
SSC-Insane
SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)

Group: General Forum Members
Points: 22443 Visits: 15937
Well that subquery for temp table 2 is using a left join not an inner join to temp table 1.

Also, caps lock cruise control for cool.
jeffshelix
jeffshelix
SSC Eights!
SSC Eights! (939 reputation)SSC Eights! (939 reputation)SSC Eights! (939 reputation)SSC Eights! (939 reputation)SSC Eights! (939 reputation)SSC Eights! (939 reputation)SSC Eights! (939 reputation)SSC Eights! (939 reputation)

Group: General Forum Members
Points: 939 Visits: 201
I dont know what a DDL is . .. I just need the COMPOSITE PARTS from ZATS that match the PART_NUMs in #TEMP1 . . . . . sorry, very new to this.
The columns in question are all Varchar(255) if that helps.

thanks again
jeffshelix
jeffshelix
SSC Eights!
SSC Eights! (939 reputation)SSC Eights! (939 reputation)SSC Eights! (939 reputation)SSC Eights! (939 reputation)SSC Eights! (939 reputation)SSC Eights! (939 reputation)SSC Eights! (939 reputation)SSC Eights! (939 reputation)

Group: General Forum Members
Points: 939 Visits: 201
Solved, our data is whacked . . . we have 500,000 rows in pricing for the 7000 distinct parts in temp 1

thanks
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search