Click here to Skip to main content
15,898,538 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
I have a Dynamic SQl Query as below

Create #TempTable(ColumnA int, ColumnB int, ColumnC Int)

Insert into #TempTable(select A,B,C from Table1 where  some condition formed dynamically)
Insert into #TempTable(select A,B,C from Table1 where  some condition formed dynamically)
Insert into #TempTable(select A,B,C from Table1 where  some condition formed dynamically)
Insert into #TempTable(select A,B,C from Table1 where  some condition formed dynamically)
Insert into #TempTable(select A,B,C from Table1 where  some condition formed dynamically)

select * from #TempTable
drop table #TempTable


Note : The Number of insert statements into the #TempTablecan vary from 10 to 100 hence it takes a lot of time to execute

What i wanted to know is , Is There a way in SQL server 2008 R2 using which i can execute the Insert statements parallely and Reduce the Execution Time??
Posted
Updated 11-Jun-14 21:06pm
v2
Comments
Magic Wonder 12-Jun-14 3:05am    
Are your where conditions varying every time? You can club those where conditions if possible and execute it in single insert statement.
David Boon 12-Jun-14 4:51am    
Yup the where condition is different for every insert
Magic Wonder 12-Jun-14 5:38am    
Okay then you can do one thing that create a loop to pass your dynamic where conditions to your insert query. This is the way you can avoid writing n nos of query at least.
Thava Rajan 12-Jun-14 3:23am    
i go with you magic

1 solution

if your condition is not varying at every row then try that.. :)

SQL
SELECT * INTO #TempTable FROM SourceTable WHERE.....--condition 
 
Share this answer
 
v3
Comments
HardikPatel.SE 12-Jun-14 3:41am    
5+

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900