Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to create Counter variable in Foreach loop container SSIS 2008

Posted on 2011-02-28
4
Medium Priority
?
1,385 Views
Last Modified: 2013-11-10
Hi There,

I was working on creating counter variable inside foreach loop container because, I'm having data like this

(stocknumber_randomID)
00005543_10                      
00005543_12                      
00005543_4564                  
00006644_567                    
00006644_768  

and desired output

(stocknumber_randomID)   NEW SEQUENCE
00005543_10                      1
00005543_12                      2
00005543_4564                  3
00006644_567                    1
00006644_768                    2
and so on.....

If I can use counter in foreach loop I can achieve this. Could you please suggest me how to setup incremental counter inside foreach loop

Thanks
Vamsi,
0
Comment
Question by:vepak
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 26

Expert Comment

by:tigin44
ID: 35002061
you may use the ROW_NUMBER function ie...

SELECT stocknumber_randomID, ROW_NUMBER() OVER (PARTITION BY LEFT(stocknumber_randomID,CHARINDEX('_',stocknumber_randomID-1)) ORDER BY stocknumber_randomID) AS newSequence
FROM yourTable
0
 

Author Comment

by:vepak
ID: 35002314
it says
Conversion failed when converting the varchar value '00003311_6718.jpg' to data type int.

as I have file names as 00003311_6718.jpg and so on....
0
 
LVL 26

Accepted Solution

by:
tigin44 earned 2000 total points
ID: 35002379
a misplaced paranthesisi  correct one is this

SELECT stocknumber_randomID, ROW_NUMBER() OVER (PARTITION BY LEFT(stocknumber_randomID,CHARINDEX('_',stocknumber_randomID)-1) ORDER BY stocknumber_randomID) AS newSequence
FROM yourTable
0
 

Author Comment

by:vepak
ID: 35002434
Thanks man it worked. Awesome.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to shrink a transaction log file down to a reasonable size.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question