Urgent---- Usinging t-sql in Foreach loop with recordset

Hi All,
       I am new to SSIS 2012.  I am trying to create a package that will loop through a control table and perform a series of task per record.  To be more clear this is what i am trying to do.
    *   Read a control plan table into recordset objPlan with 10 columns.  ( this seems to be working fine )  
    *   Do a Foreach loop that will run a
t-sql task to delete all records from an output table then load new data.  (not working)
         @[User::var_Plan_dim] ( is one of the columns on the record set) this is indexed as 1
         I have tried to do a t-sql command
                     delete from table where plan = @[User::var_Plan_dim] ( this does not work )
                     ** I have ResultsSetType set to ResultSetType_None any other options causes error????
        Could you send me a link or show me an example of what the configuration should be for the
Foreach and T-SQL should be? 
Thank you in Advance!!!!
I have working on this for days without any luck and I could really use your help...
DH
DHowe

Hi hsbal,
        I have worked my way through that with your help Thank You...  
        But i am having another issue now, in the foreach loop i have 12 variable
      variable                                 index
       User::objplan                       0                        
object
       User::var_Plan _ dim            1   etc....             string
       User::var_provider_status     11                      string
       when i run the process i get this error:
Error: The enumerator failed to retrieve element at index "11".
Error: ForEach Variable Mapping number 11 to variable "User::var_provider_status" cannot be applied.
Error: The enumerator failed to retrieve element at index "11".
Error: ForEach Variable Mapping number 11 to variable "User::var_provider_status" cannot be applied.
        So should the object variable be indexed 0?  I tried taking the objplan off the list of variable and renumber 0-10 and the program didn't like index "1" with the same error, do I don't think
it is really column/field related.
Thanks,
Dawn
DHowe

Similar Messages

  • Setup ForEach Loop with 2D Array

    Hello All,
      Would like to know how (if possible) to configure the "ForEach Loop" step in TestStand for an empty 2D Array.  What I have is a 2D array of character strings that represent sets of configuration parameters (i.e. each row contains several columns of parameters, and there are an undetermined amount of rows).  With the ForEach Loop, I would want it to loop once for each parameter row (not for each column of each row).  Right now it looks like it runs once for every column.  Please advise.  Thanks much.
    Regards,
    GSinMN     

    Hi GSinMN    
    There’s a TestStand known issue of transposing an incoming array from LabVIEW, if you are importing and array from LabVIEW you can transpose that array prior to pass it to TestStand. Because seems that the behavior you are seeing is due to a transposed array.
    Here are some links with more information
    http://www.ni.com/white-paper/8681/en/#161523_by_Category
    http://forums.ni.com/t5/NI-TestStand/TestStand-Foreach-tutorial-or-example/td-p/1125230
    regards
    Chris S.

  • How can you see the progress when using a ForEach loop?

    Hi,
    I have an array with about 100 containers in it. My main thread uses a ForEach loop with an inner case structure with six possibilities. My previous program had all the steps in a very long list, executing them one by one. I find this new approach is much nicer to look at, and easier to change, but there isn't really any way of telling how far along the test is (unless you know it by heart). In the long list approach, you could see all the Done/Passed outcomes and how many remained, now there is no way of telling.
    Any tips on making some kind of progress indication? 
    Solved!
    Go to Solution.

    As ObjectReference parameter, you should use 'Nothing'. The last parameter (synchronuous?) you can choose true or false. Please refer to the documentation of PostUIMessageEx for further information.
    The numeric parameter should range between 0-100. Since it is "Progress Percent", this makes sense, does it?
    The status bar has several panes, one e.g. displaying the logged in user or the used process model. The pane on the right most side will display the Progress Percent if used in your sequence.
    The default reporting, as already stated, includes this feature. So if you have a sequence with e.g. 500 steps, the reporting "will have a visible progress" in that pane (with less than 100 steps, it is most often too fast to see). Remember that NI Sequence Editor and the Full Featured User Interfaces do have this feature, the Simple UI does not have it.
    Norbert
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.

  • How can I load a .xlsx File into a SQL Server Table using a Foreach Loop Container in SSIS?

    I know I've REALLY struggled with this before. I just don't understand why this has to be soooooo difficult.
    I can very easily do a straight Data Pump of a .xlsX File into a SQL Server Table using a normal Excel Connection and a normal Excel Source...simply converting Unicode to DT_STR and then using an OLE DB Destination of the SQL Server Table.
    If I want to make the SSIS Package a little more flexible by allowing multiple .xlsX spreadsheets to be pumped in by using a Foreach Loop Container, the whole SSIS Package seems to go to hell in a hand basket. I simply do the following...
    Put the Data Flow Task within the Foreach Loop Container
    Add the Variable Mapping Variable User::FilePath that I defined as a Variable and a string within the FOreach Loop Container
    I change the Excel Connection and its Expression to be ExcelFilePath ==> @[User::FilePath]
    I then try and change the Excel Source and its Data Access Mode to Table Name or view name variable and provide the Variable Name User::FilePath
    And that's when I run into trouble...
    Exception from HRESULT: 0xC02020E8
    Error at Data Flow Task [Excel Source [56]]:SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occured. Error code: 0x80004005.
    Error at Data Flow Task [Excel Source [56]]: Opening a rowset for "...(the EXACT Path and .xlsx File Name)...". Check that the object exists in the database. (And I know it's there!!!)
    I don't understand by adding a Foreach Loop Container to try and make this as efficient as possible has caused such an error unless I'm overlooking something. I have even tried delaying my validations and that doesn't seem to help.
    I have looked hard in Google and even YouTube to try and find a solution for this but for the life of me I cannot seem to find anything on pumping a .xlsX file into SQL Server using a Foreach Loop Container.
    Can ANYONE please help me out here? I'm at the end of my rope trying to get this to work. I think the last time I was in this quandry, trying to pump a .xlsX File into a SQL Server Table using a Foreach Loop Container in SSIS, I actually wrote a C# Script
    to write the contents of the .xlsX File into a .csv File and then Actually used the .csv File to pump the data into a SQL Server Table.
    Thanks for your review and am hoping and praying for a reply and solution.

    Hi ITBobbyP,
    If I understand correctly, you want to load data from multiple sheets in an .xlsx file into a SQL Server table.
    If in this scenario, please refer to the following tips:
    The Foreach Loop container should be configured as shown below:
    Enumerator: Foreach ADO.NET Schema Rowset Enumerator
    Connection String: The OLE DB Connection String for the excel file.
    Schema: Tables.
    In the Variable Mapping, map the variable to Sheet_Name, and change the Index from 0 to 2.
    The connection string for Excel Connection Manager is the original one, we needn’t make any change.
    Change Table Name or View name to the variable Sheet_Name.
    If you want to load data from multiple sheets in multiple .xlsx files into a SQL Server table, please refer to following thread:
    http://stackoverflow.com/questions/7411741/how-to-loop-through-excel-files-and-load-them-into-a-database-using-ssis-package
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Can I append the file name from a Foreach Loop Container Enumerator into a SQL Server Statement?

    I would like to pass back via an Email the name of the file that was successfully FTP'ed to a remote server. And I was hoping to do this via an Execute SQL Task with the following SQL Statement...but I just don't know if it will append the Foreach Loop Container
    variable enumerator to the appended Email message that I am building in SQL Server or if I can and how I can...
    I sort of get the feeling that I can try and do this via Dynamic SQL...I just don't know if by building dynamic SQL if my Foreach Loop Container enumerator variable will be appended to my Email Message via the SQL Server UPDATE 
    @[User::FTPFHFileName]
    Or do I add a Data Flow Task and an OLE DB Command and pass the Foreach Loop Container enumerator variable to a Stored Procedure referenced in the OLE DB Command via a "?"
    Thanks for your review and am hopeful for a reply.

    Hello,
    It seems that the issue had been solved and thanks for your sharing. It will be very beneficial for other community members who have similar questions.
    I’d like to mark this issue as "Answered". Please also feel free to unmark the issue, with any new findings or concerns you may have.
    Regards,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Strange issue with rights of account, used by SSIS (Foreach Loop Container does not return file names without Admin rights on server)

    Hello everyone.
    Faced very strange issue with account, which is used to run SSIS package.
    The specific package uses Foreach Loop Container to retrieve file names within the specified folder, and put them into Import file task.
    The package is set up to run under specific service account. This service account is given all permissions (Full control) to the folder where source files reside.
    So the issue is: SSIS package fails to execute this task (Foreach Loop Container and then Import), and shows that no files are found in the directory (although files ARE there).
    Once we're adding the service account into local Administrators group on the SQL Server, it works! Removing - does not work again. We cannot leave the service account as SQL server's admin as it's prohibited by our IT policies, and is just a bad practice.
    Any ideas, please? 
    MCP

    Here's the real log output:
    Date 16.04.2014 12:47:09
    Log Job History (RU-BW: Update)
    Step ID 1
    Server Server
    Job Name RU-BW: Update
    Step Name bw_import_cust_master_data
    Duration 00:00:02
    Sql Severity 0
    Sql Message ID 0
    Operator Emailed
    Operator Net sent
    Operator Paged
    Retries Attempted 0
    Message
    Executed as user: service_account Microsoft (R) SQL Server Execute Package Utility  Version 10.50.4286.0 for 64-bit  Copyright (C) Microsoft Corporation 2010. All rights reserved.    Started:  12:47:09  Error: 2014-04-16 12:47:11.45
        Code: 0xC0202070     Source: bw_import_cust_master_data Connection manager "Input"     Description: The file name property is not valid. The file name is a device or contains invalid characters.  End Error  Error:
    2014-04-16 12:47:11.47     Code: 0xC0202070     Source: bw_import_cust_master_data Connection manager "Input"     Description: The file name property is not valid. The file name is a device or contains invalid characters.  End
    Error  Error: 2014-04-16 12:47:11.48     Code: 0xC0202070     Source: bw_import_cust_master_data Connection manager "Input"     Description: The file name property is not valid. The file name is a device or contains invalid
    characters.  End Error  Error: 2014-04-16 12:47:11.48     Code: 0xC020207E     Source: Import file Flat File Source [1]     Description: The file name is not valid. The file name is a device or contains invalid characters.
     End Error  Error: 2014-04-16 12:47:11.48     Code: 0xC004701A     Source: Import file SSIS.Pipeline     Description: component "Flat File Source" (1) failed the pre-execute phase and returned error code 0xC020207E.
     End Error  DTExec: The package execution returned DTSER_FAILURE (1).  Started:  12:47:09  Finished: 12:47:11  Elapsed:  2.324 seconds.  The package execution failed.  The step failed.
    MCP

  • ForEach Loop Container Mapping Variable From SSIS Package Not Working In SQL-Server StoredProcedure

    I have an SSIS package that uses a ForEach Loop Container to enumerate Excel Files in a dir. I also have a Task Flow that inserts data from those Excel files into SQL-Server.
    Im trying to insert the file names into a column into the same table in SQL-Server by using a mapping variable in my StoredProcedure.
    Im having trouble with my MappingVariable at the end of the script with red squigglies. The following is my StoredProcedure script.
    CREATE PROCEDURE [dbo].[Insert_F_STG_v2]
    -- Add the parameters for the stored procedure here
    @Hrs float,
    @Type nvarchar(100),
    @SN nvarchar(100),
    @Op nvarchar(100),
    @[USER::CurrentFileName]
    AS
    BEGIN
    SET NOCOUNT ON;
    INSERT INTO [CRM_RC].[dbo].[F_StgTbl]
    [Hrs],
    [Type],
    [SN],
    [Op],
    [Report_Date]
    VALUES
    @Hrs ,
    @Type,
    @SN,
    @Op,
    @[USER::CurrentFileName]
    END
    The last @[USER::CurrentFileName] in the Values block at the bottom of the script is the one giving me issues.
    The following is the error:
    Msg 102, Level 15, State 1, Procedure Insert_F_STG_v2, Line 95
    Incorrect syntax near 'USER::CurrentFileName'.

    This seems to be the solution, but get the following exception: 
    [Derived Column [2]] Error: The "Derived Column" failed because truncation occurred, and the truncation row disposition on "Derived Column.Outputs[Derived Column Output].Columns[Derived Column 1]" specifies failure on truncation. A truncation error occurred
    on the specified object of the specified component.
    AND:  [SSIS.Pipeline] Error: SSIS Error Code DTS_E_PROCESSINPUTFAILED.  The ProcessInput method on component "Derived Column" (2) failed with error code 0xC020902A while processing input "Derived Column Input" (3). The identified component returned
    an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running.  There may be error messages posted before this with more information about the failure.

  • SSIS - Script Task creates a DTS var and using Foreach loop, Execute SQL needs to INSERT into table from this DTS var.

    I have a script task written in C# that creates an array of strings "arrayFields" after parsing a text file. It saves the array of strings in a DTS variable.
    Each row in array represents a row is comma separated and is a row that must be inserted into a table. For example,
    X and Z are fields in the table
    X1, X2,....Xn
    Z1,Z2,...Zn
    I am using a Foreach Loop  to grab each row and then  Execute SQL Task to take each row from the array and insert each field per row in a table,
    The SQL is something like,
    INSERT dbo.table values(field1, field2,...fieldn) arrayFields?
    What should this this INSERT look like?

    I guess you implemented
    Shredding a Recordset
    Based on what I understood (correct me if I am wrong) you have difficulties mapping the input parameters, if so here is the guide
    http://www.sqlis.com/sqlis/post/The-Execute-SQL-Task.aspx
    In short it might look like
    INSERT dbo.table  (ColumnA, ColumnB,...) VALUES (?,?...)
    The syntax for the T-SQL INSERT is http://technet.microsoft.com/en-us/library/dd776381%28v=sql.105%29.aspx
    Arthur
    MyBlog
    Twitter

  • Trouble with nested foreach loop

    I got 3 nested foreach loop but the 2nd and the third one outputs no data.
    $vss = "vSwitch3"
    $vmhost_array = @("host1,host2,host3")
    $vss_vlan_array = @("vlan50")
    $dvs_vlan_array = @("n1kv_vms_vlan50")
    foreach ($vmhost in $vmhost_array) {
    foreach ($vss_vlan in $vss_vlan_array) {
    foreach ($dvs_vlan in $dvs_vlan_array) {
    Get-VMHost $vmhost | Get-VirtualSwitch -Name $vss | Get-VirtualPortGroup -Name $vss_vlan | Get-VM | Get-NetworkAdapter | Set-NetworkAdapter -Portgroup $dvs_vlan -Confirm:$false
    I get runtime error at Get-VirtualSwitch -Name $vss 
    $vss says vlan50 not found. but its there. anything wrong with this nested foreach?

    hi
    I am actually getting an error on 
    Get-VirtualPortGroup -Name $($vss_vlan_array[$i])
    Its trying to give me the whole array instead of the 1st item in the array. so get-virtualportgroup will fail.
    I checked it with $vss_vlan_array[0] and gives me 
    "vlan50","vlan49"
    how do one item at a time instead of the whole array?

  • Is it possible to load multiple .xlsx files into a SQL Server Table using SSIS and a Foreach Loop Container when each Excel spreadsheet is comprised of two different worksheets

    So we have an Invoice .xlsx File from a 3rd party vendor. It contains two worksheets..."Enrolled" and "Engaged". The data and data columns in each worksheet is different. Is it possible to loop through multiple .xlsx files using SSIS
    and a Foreach Loop Container for each spreadsheet, and then another Foreach Loop Container to control each worksheet, and pump the Excel data into a SQL Server Table first for "Enrolled" and then for "Engaged"? How can I control the Foreach
    Loop Container in SSIS to process ONLY the "Enrolled" worksheet first? And then the "Engaged" worksheet next?
    I know I have multiples out here and I apologize for that...but right now it seems as though I take three steps forward and then two back.
    Any help would be GREATLY appreciated!
    Thanks in advance!

    If the structure of the Excel sheets does not change from file to file then you can by having one ForEach Loop processing always the "Enrolled" sheet and another always the "Engaged" this is doable because the Excel OLEDB connector allows
    to pick individual sheets, it is problematic therefore when sheet names themselves change.
    MSDN has an example: https://msdn.microsoft.com/en-ca/library/ms345182.aspx
    Arthur
    MyBlog
    Twitter

  • Foreach Loop Container with a Data Flow Task looking for file from Connection Manager

    So I have a Data Flow Task within a Foreach Loop Container. The Foreach Loop Container has a Variable Mapping of User:FileName to pass to the Data Flow Task.
    The Data Flow Task has a Flat File Source since we're looking to process .csv Files. And the Flat File Source has a Flat File Connection Manager where I specified the File name when I created it. I thought you needed to do this even though it won't really
    use it since it should be getting its File name from the Foreach Loop Container. But when attempting to execute, it is blowing up because it seems to be looking for my test file name that I indicated in the Flat File Connection Manager rather than the file
    it should be trying to process in User:FileName from the Foreach Loop Container.
    What am I doing wrong here??? I thought you needed to indicate a File name within the Flat File Connection Manager even though it really won't be using it.
    Thanks for your review...I hope I've been clear...and am hopeful for a reply.
    PSULionRP

    The Flat File Connection manager's Connection String needs to be set to reference the variable used in the ForEach Loop:
    Arthur My Blog

  • Help with forEach loop

    I have a JSTL forEach loop similar to below:
    <c:forEach var="product" items="${sessionScope.products}">
         <tr><td>${product.description}</td></tr>
    </c:forEach>I would like to use a static class to format the description. Something like below, but I know I cannot do it this way. How can I accomplish this?
    <tr><td>${ProductFormatter.getHtmlDescription(product)}</td></tr>thanks

    The least change approach. If you have already have a static function to do this, then a function tag would be appropriate.
    The function tag basically lets you call a static function from EL.
    custom.tld
    <?xml version="1.0" encoding="UTF-8" ?>
    <taglib xsi:schemaLocation="http://java.sun.com/xml/ns/javaee web-
            jsptaglibrary_2_1.xsd" xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1"
    >
         <tlib-version>1.0</tlib-version>
         <short-name>my</short-name>
         <uri>http://www.mytags.com/</uri>
         <function>
              <name>productFormatter</name>
              <function-class>com.mypackage.ProductFormatter</function-class>
              <function-signature>java.lang.String getHtmlDescription(com.mypackage.Product)</function-signature>
         </function>     
    </taglib>If you include that tld in your WEB-INF directory, then the following in a JSP should work:
    <%@ taglib uri="http://www.mytags.com/" prefix="my"%>
    <c:forEach var="product" items="${sessionScope.products}">
         <tr><td>${my:productFormatter(product)}</td></tr>
    </c:forEach>Rather than putting the code in a static function, you might be better off encoding the logic into a custom tag. It depends on what your formatting function is like.
    cheers,
    evnafets

  • Power-shell distribution list update Managedby with foreach loop

    The script function is to find a user that is listed a a manager/owner on a distribution list and then replace that manager. The issue is I'm unable to replace the manager when they are a owner/manager of multiple distribution list. The script is successful
    if I remove the foreach loop and just run the script on one distribution list. Please see error message below. Any help is appreciated. 
    $user = "eharris"
    #$DLSimilarmgr = "harris, aaron m"
    $username = (get-aduser $user).name
    $listDLgroup = get-distributiongroup -resultsize unlimited | where {$_.managedby -like "*$username*"} |fl name
    $Foreach ($GrpDL in $listDLgroup) {
       $listDLManager = $GrpDL.ManagedBy 
       $NewDLManager = get-user -id "aharris"  
       $listDLManager+= $NewDlManager 
       set-distributiongroup $GrpDL -managedby $listDLManager -BypassSecurityGroupManagerCheck
    Aaron Harris ExchangeSharePointGuy

    Having issue combing the two scripts. The first scripts gets the DL managers. The second script will update the managed by field of the users and the previous managers of the DL. However, I don't know how to update a multiple DL when the user is listed as
    a manager of more than 1 DL at a time. In script 2 I would like to update the multiple return value for script 1. Any help would be appreciated. 
    #script 1 list the dl's the users is a manager of 
    $user = "eharris"
    $username = (get-aduser $user).name
    $listDLgroup = get-distributiongroup -resultsize unlimited | where {$_.managedby -like "*$username*"} |fl name
    #Script 2 working gets the dl and adds the new member and the previous members of that DL
    $GrpDL = Get-DistributionGroup -id "#365DLTest"
    $listDLManager = $GrpDL.ManagedBy $NewDLManager = get-user -id "eharris" 
    $listDLManager+= $NewDlManager set-distributiongroup "#365DLTest" -managedby $listDLManager -BypassSecurityGroupManagerCheck
    Aaron Harris ExchangeSharePointGuy

  • Using foreach loop container with file system task to rename and move files

    the foreach loop container will not rename and move files for me
    sukai

    duplicate of
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/8f2899f1-43b0-47e0-8bd0-e082989cdcb8/file-system-task-and-foreach-loop-container?forum=sqlintegrationservices
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • SSIS BULK INSERT unsing UNC inside of ForEach Loop Container Failed could not be opened. Operating system error code 5(Access is denied.)

    Hi,
    I am trying to figure out how to fix my problem
    Error: Could not be opened. Operating system error code 5(Access is denied.)
    Process Description:
    Target Database Server Reside on different Server in the Network
    SSIS Package runs from a Remote Server
    SSIS Package use a ForEachLoop Container to loop into a directory to do Bulk Insert
    SSIS Package use variables to specified the share location of the files using UNC like this
    \\server\files
    Database Service accounts under the Database is runing it has full permission on the share drive were the files reside.
    In the Execution Results tab shows the prepare SQL statement for the BULK insert and I can run the same exact the bulk insert in SSMS without errors, from the Database Server and from the server were SSIS package is executed.
    I am on a dead end and I don’t want to re-write SSIS to use Data Flow Task because is not flexible to update when metadata of the table changed.
    Below post it has almost the same situation:
    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/8de13e74-709a-43a5-8be2-034b764ca44f/problem-with-bulk-insert-task-in-foreach-loop?forum=sqlintegrationservices

    Insteresting how I fixed the issue, Adding the Application Name into the SQL OLAP Connection String Fixed the issue. I am not sure why SQL Server wasn't able to open the file remotely without this.

Maybe you are looking for

  • Unable to share a fat32 partition with macs (snow leopard)

    i have a hard drive with two partitions in it, im able to share one of them formated for mac, but im not able to share the fat32 partition? what is going on? it is connected to an imac (snow leopard) trying to share it with macbook pro and windows pc

  • Button onclick not working in the calculated field

    Hi Everyone, I have to add the button in the calculated field through list definition. On click of button it should call the java script function. I can add the button but on click event is not working. this is my code: <Field Name="Accept" ID="{1F73

  • Journal import fails when called from PLSQL

    Hi, When journal import is called from plsql code it is failing with error in 'gllacc() Function returning without value and no data found'. Same transaction is run succesfully from front end. I checked both gl_interface and gl_interface_control tabl

  • How to close FPGA reference out from different while loop

    Hi Friends,               I`ve different while loop which performs the FPGA read port on different loops I`ve the FPGA out on every terminal at the end of the while loop. I`ve just connected the merge error function in which all the error out of the

  • Customer - vendor is same ...clearing

    Hi, we have same customer and vendor .. so in master record i did the configuration Now . Business need .. Customer invoice   $ 500 customer paid :     $ 400                         and we r using residual pmt So system will generate $100 financial d