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 2008 Forums
 SSIS and Import/Export (2008)
 cursors in ssis

Author  Topic 

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2011-07-05 : 08:20:10
Hi,
I am using a cursor inside the stored procedure to loop through rows and place values into variables i.e. @dsss, etc.
Is there such a fuunctionality in SSIS or should I just use the execute sql task to execute this sql with cursor in it?

Thanks

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-07-05 : 08:53:32
Well ssis uses row based processing in the dataflow so you probably already have the functionality.

==========================================
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.
Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2011-07-05 : 09:10:44
Basically in my storedprocedure which is huge, there are several cursors and for each cursor, there are if statements. And for each if statement, there are insert and updates based on the variables passed from the cursor.
Can I simplify this stored procedure into a SSIS package?
Thanks
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2011-07-05 : 09:18:01
I think you can use a SCD for this, if you insist in using SSIS.

But why use SSIS? I think you can use MERGE command to do this.


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

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-07-05 : 09:33:17
Even if you don't use MERGE, you can dump the cursor. There's an example here (scroll down a bit): http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=47319

Plus a lot of stuff about why cursors are bad.
Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2011-07-05 : 09:50:47
quote:
Originally posted by SwePeso

I think you can use a SCD for this, if you insist in using SSIS.

But why use SSIS? I think you can use MERGE command to do this.


N 56°04'39.26"
E 12°55'05.63"



Do you mean to use a ssis package with merg join task in it?
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-07-05 : 09:54:29
Not a merge join, and not SSIS, but this: http://technet.microsoft.com/en-us/library/bb510625.aspx
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-07-05 : 09:56:22
No - a merge staement in the sp.
It depends a lot on what the code actually is.

The question is really why you want to use ssis for this.

You can import the output of an sp into an object then loop through that - sounds a bit like you want to call a package from within a cursor stting variables - which is easy but probably not a good idea.

==========================================
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.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2011-07-05 : 09:58:53
Try to solve the problem without SSIS first.
We can't help you since we don't know what you are trying to accomplish.



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

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2011-07-05 : 10:14:12
quote:
Originally posted by nigelrivett

No - a merge staement in the sp.
It depends a lot on what the code actually is.

The question is really why you want to use ssis for this.

You can import the output of an sp into an object then loop through that - sounds a bit like you want to call a package from within a cursor stting variables - which is easy but probably not a good idea.

==========================================
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.


just to re-elaborate my query.
I have a large stored proc in which there are several cursors and a lot of if statements. For each if statement, there are update and insert statements with the @variables passed by cursors.
Question is, can I simplify this Stored proc by placing the logic into a ssis package?
Thanks
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-07-05 : 10:17:53
Probably not - you can probably simplify the logic but the issue is translating the requirements rather than the technology used.
You can probably get rid of the cursors in the SP which would simplify that but just translating to ssis would probably make it more complicated.

==========================================
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.
Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2011-07-05 : 10:29:19
quote:
Originally posted by nigelrivett

Probably not - you can probably simplify the logic but the issue is translating the requirements rather than the technology used.
You can probably get rid of the cursors in the SP which would simplify that but just translating to ssis would probably make it more complicated.

==========================================
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.


Let it me put it this way;
In execute sql task i.e. SQL1. I am executing a select statement.
i.e. select field1, field2, field3, etc from table1...
for each row, I want to pass the value of Field1 to the next sql task i.e. SQL2.
Thanks
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-07-05 : 10:34:07
No simpler on ssis than t-sql.
The problem sounds like the underlying design.

==========================================
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.
Go to Top of Page
   

- Advertisement -