I have 4 columns in an excel file. I need to assign values from each row to the corresponding 4 variables so they can be replaced lated in a query i am doing on a server.
My question is: How to do that?
So far i tried doing an SQL task in which i create a table with 4 columns (having the same names as those in my excel file) and a task to transfer the content of the excel to a recordset destination which stores the results into a variable. I also created a foreach loop in which i am having my tasks. What am I missing, how can I do this?
Thanks
EDIT
please find below a screenshot from my project. This is the overview.
In "Execute SQL Task" there is a connection to excel and has the following statement
CREATE TABLE tempVariableMapping
(
AsofDate varchar(20),
Assump_Set varchar(20),
MarketName varchar(20),
Portname varchar(20)
);
Then in the transfer task (in the recordset destination), i'm assigning the variable name to User::RecordSetOutput which is a global variable of type object.
In foreach loop i'm using a foreach ado enumerator and pointing to that User::RecordSetOutput variable find below the variable mapping
Those 4 variables in variable mapping are those in which i want to pass the values from each row of the excel file.
The sequence container and create temp table are just dummy. Haven't figured out the correct way. Everything below that, works.
Sorry for the missunderstanding, hope this is enough to get the picture.
Thank you for your time and help
Related
apologies in advance if this question was previously raised, but I couldn't find the answer anywhere.
Does anyone know if there is a way to turn off or ideally set auto data type identification to "Short Text"? I believe MS Access looks at the first 24 rows and applies data type for the table. In my case first 24 (in fact 1000s ) of first column data might be a Number but I need to be Short Text as some of the numbers are alphanumeric.
So I'm importing (linking) .CSV file first to a temp table then passing data to another table via ODBC connection. So is there a way to make sure that in temp table "tblrsSLPARENTTEMP" data type will always be set as "Short Text"?
Set db = CurrentDb
On Error Resume Next: db.TableDefs.Delete "tblrsSLPARENTTEMP": On Error GoTo 0
db.TableDefs.Refresh
DoCmd.TransferText TransferType:=acLinkDelim, TableName:="tblrsSLPARENTTEMP", _
FileName:=strPathFile, HasFieldNames:=True
db.TableDefs.Refresh
Note:
Columns in .CSV file might change places, so one day data in column A could be in column B the next day.
I need to know column names, so HasFieldNames:=False wouldn't be an option
After importing the data to access,then you can change the field type by is name like
CurrentDb.Execute "ALTER TABLE YourTableName ALTER COLUMN YourColumnName VARCHAR(255);" ,dbFailOnError
Change YourTableName to Your Table Name and so on.
Execute this line for each field you need to change.
Not sure if this is going to be useful for anyone, but couldn't find a solution in Access, so what I did that worked was:
Created a VBA in Excel to insert 50 lines of alphanumeric text in CSV file and save it
Import into Access DB.
Is created linked DB with a short text data type. Not the cleanest solution but it works :)
I was wondering if it is possible to insert the row being read by a for each loop in SSIS into another table. As the resultset is being processed by the foreach loop, i want to store the values in the table so they can be referenced again later in my project.
The result set is being stored in a global variable (object).
I'm not sure if this is clear. Please help me think through the problem. Thanks for your time!!!
You can add a DataFlow Task before the foreach Loop and Read the values from the Object variables as Source:
Using The SSIS Object Variable As A Data Flow Source
Creating a Source with the Script Component
I am trying to do a basic dataflow task in SSIS2012 where the destination is a Netezza table. I have a column that I named "Transaction_ID" that I am planning to use as a primary key and I have a sequence ready to populate it (Seq_Transaction_ID). However, I am not sure how exactly to assign the sequence.
For instance I tried making the table and assigning the column to a default of the next value for the sequence and got an error "you can only use a next value function within a target list". I'm also not sure how I would get the sequence into SSIS either.
Any ideas?
Thank you,
I need guidelines to do a task. I am new to work in SSIS & I only its very basics. But I can try to do it myself if someone guides me to choose the appropriate tools & how to do it. The task I've divided in to series of steps. Please help me to create this project
Step 1: retrieve Employee_ID's from a table in SQL Server
select disctinct(employee_id)
from emp_details
Step 2: retrieve attendance details from another table for every employee_id retrieved in the previous step.
select * from emp_attendance
where employee_id = ....
Step 3: write all the records retrieved to a text file. The name of the text file should be the employee id.
For ex: for employee id 1234, a file should be generated in the specified path with the file name 1234.txt with that employee's attendance details inside it. I.e the records retrieved from step 2 Inside it.
How can I achieve this task? What all tools must I use & what is the logic. Plz guide me friends.
Thanks in advance :-)
Here is a summary of the solution in the posted link:
Use a SQL Task to populate a SSIS object variable with a recordset containing the list of employee_is
Iterate through the object variable using a for each ADO enumerator
In the for each ADO enumerator, map the employee_id column in your SSIS object variable to individual a string or integer SSIS variable called employee_id
Inside the for each ADO enumerator, use a data flow task to transfer data from the DB to a text file
Use the employee_id column mapped in step 3 as a parameter in your source SQL in step 4 to limit the dataset to a single employee for each iteration
Use the employee_id column mapped in step 3 in an expression in your file connection manager to dynamically build the output file name
I've few excel source files in one folder in SSIS. I want to pull data from these excel files and load in to SQL tables.
My problem is I want to save all the files names one by one and want to create SQL table with exactly same name as filename
and then want to load each excel file in corresponding table.
Please help me how to create a package for this.
Jayvee has presented the high level view which is good enough! Let me add in bit detail.
I am assuming that you have dynamic Excel file connection.
Declare a variable and named it as FileName. And assign it the first file name which is available in the folder.
Place Foreach Loop Container and double click on it. Specify the Folder: and Files: as shown in image below.
In the same Foreach Loop Editor, go to Variable Mappings. Select Variable from drop down list. This is the same variable which we defined in first step. Set its Index to 0. Click OK.
Remaining task is same as Jayvee explained.
See this link for further help. And this for Result Set Property Not Set Correctly. I think setting ResultSet property to SingleRow will do the job.
your control flow should look like this: