Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
easy_goer
Starting Member
21 Posts |
Posted - 2013-10-01 : 10:12:34
|
Hello. I ran the following script that too 3 hours 25 minutes to insert about 40,000 rows. Is there any logic that I can put into this to speed it up? Thank you!insert into T3select T2.COL1, T2.COL2, T1.COL1, T1.COL2, T1.COL3from T1join T2 on T1.COL4 = T2.COL3where T2.COL4 != 'data1'and T1.COL1 is not NULLand T1.COL5 is not NULLand T1.COL6 = 'data2'and CAST (T2.COL1 as VARCHAR)+'-'+CAST(T2.COL2 as VARCHAR)+'-'+CAST(T1.COL1 as VARCHAR)+'-'+CAST(T1.COL2 as VARCHAR) not in(select CAST(COL1 as VARCHAR)+'-'+CAST(COL2 as VARCHAR)+'-'+CAST(COL3 as VARCHAR)+'-'+CAST(COL4 as VARCHAR) from T3) |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2013-10-01 : 10:38:37
|
depends which part is taking the time.you could try this if the datatypes on T2 and T3 matchinsert into T3select T2.COL1, T2.COL2, T1.COL1, T1.COL2, T1.COL3from T1join T2 on T1.COL4 = T2.COL3left join T3on T2.COL1 = T3.COL1and T2.COL2 = T3.COL2and T2.COL3 = T3.COL3and T2.COL4 = T3.COL4where T2.COL4 != 'data1'and T1.COL1 is not NULLand T1.COL5 is not NULLand T1.COL6 = 'data2'AND t3.col1 IS NULL==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
|
|
easy_goer
Starting Member
21 Posts |
Posted - 2013-10-03 : 00:14:17
|
Got it. Thanks for the help! |
|
|
|
|
|