Solved

How to create Counter variable in Foreach loop container SSIS 2008

Posted on 2011-02-28
4
1,375 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 500 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Suggested Solutions

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

739 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