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.

 All Forums
 SQL Server 2005 Forums
 SSIS and Import/Export (2005)
 Can i have > 1 sql statement in Execute sql task

Author  Topic 

dhani
Posting Yak Master

132 Posts

Posted - 2008-11-12 : 16:12:21

Hello All,

in my SSIS package
i have to do the below

step 1)If index exists on tablex then remove it
step 2)then all data from tablex
step 3)then load data from source file to tablex
step 4)then create index on the tablex

here my doubt is can't i do it all first two steps in one Execute Sql Task (if yes then what is separator between sql statements)

Best Regards
asin

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2008-11-12 : 17:02:23
What were the results when you tried it to see what would happen?



CODO ERGO SUM
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-12 : 23:48:38
its better to have seperate tasks for each step with error logging for each for ease of debugging. i think sequence of tasks for above scenario should be as follows

1.execute sql task to drop index
2. execute sql task to truncate table
3.data flow task with flat file source & oledb destination
4.execute sql to recreate index
Go to Top of Page

dhani
Posting Yak Master

132 Posts

Posted - 2008-11-13 : 11:14:21
Hello All,

thank you for your answers,

what i did was took one Execute SQL task,
in that task i placed these three sql statements
1)
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[empDate]') AND name = N'empDateIndex')
DROP INDEX [empDateIndex] ON [dbo].empDate
2)
truncate table empDate
3)
CREATE NONCLUSTERED INDEX [empDateIndex] ON [dbo].[empDate]
(
[UserID] ASC,
[UserName] ASC,
[FromDt] ASC,
[ThroughDt] ASC
)

and also it could be done with sql procedure, create procedure with above three (or even more) statements then call exec procedure in Execute Sql Task

so the answer is we can execute more than 1 sql statement in Execute SQL task
Best Regards
asin
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-11-13 : 13:36:12
GO is normally used as a batch separator.


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -