How do I import TestData from csv file into Vugen Script - csv

Could some one please guide me how to do this
I would like to import Test Data from the csv file into Vugen Scripts.
Lets say I have Payee.csv file which has 28 columns of Data and csv file located some shared location. In script I need to pass the values from the csv file by importing.How can I do that in Vugen script?
I know in QTP we have DataTable.Import.
Thanks,
Raj

You can import CSV file and use it as a data file for parameterization.
Follow the steps as mentioned below:
Select the value you want to parameterize. for an explanation, I took username field (jojo).
Right click on the value (jojo) -> select Replace With Parameter -> select Create New Parameter
Write Parameter name as username (any name of your choice) -> select parameter type as File -> Click OK button.
Select Yes/No for "Do You want to replace all occurrences" based on your need.
The value (jojo) will be replaced as {Username}. Username.dat file will be created with only one entry in the file i.e., jojo
Right click on {Username} -> select Parameter Properties -> click Browse button under File Type -> Select the CSV file (Users.csv) you want to import (select Save as type -> All Files (.*) in Save As dialogue box).
Parameter Properties dailougue box shows all the entries in the csv file in tabular format.
under Select Column, select By name radio button -> from dropdown, select "username" (column header) -> click Close
Repeat the actions for each column in the CSV file, wherever you want to replace the values with data in CSV (column header is the key).
Second iteration:
For password parameter, I followed the same process, given the name parameter name as "Password", and selected the same CSV file, under refer the data "By name" -> Password (column header)
Screenshot for Password parameter:
References:
http://lrhelp.saas.hp.com/en/latest/help/WebHelp/Content/Tutorial/Preparing.htm#How2

Related

How do I create a csv file in SSRS with a .txt extension in the file name?

I have a report where I have added a data driven subscription that writes the report to a folder location on a daily schedule. The report is rendered as csv. the file name comes as MyReport1234.csv.
I need this to be Myreport1234.txt. How can I do this in SSRS?
I use SSRS 2008 R2 btw
found a solution for this:
Create a data driven subcscription
on Step 3, just write SELECT 1 or if you're trying to generate a dynamic file you could embed the logic for this in your select statement and give it an alias like SELECT 'Myreport1234.txt' as [FileName]
on Step 4, either Specify a static file name, or get the value from the database using the column "FileName" which you created in the previous step.
set the Render Format to CSV
This is the important step >> File Extension must be set to False. This will stop the renderer from adding the default extension for the renderer of your choice. leaving whatever thats on the filename to appear as the file extension.

Getting excel filename in ssis

I was wondering if anyone could help me with getting the excel (source) filename on my destination database in ssis. The database table has a column called filename (which is equal to the excel filename). Having the filename will help me with my audits. Note: I'm not a vb script person but if vb is the only way out, I'll appreciate sample script as I would have to use that in my logic. Thanks
You can use a "Derived Column" component and add a new column that contains the wanted property. I guess that you want to add a derived column that will store the "FileName" or "ConnectionString" property of your Excel Connection.
I would recommend saving the file as a CSV for multiple reasons. If it is a CSV file, you could create a flat file source for it. Then right click on the item and go to "Show Advanced Editor..." Click on the "Component Properties" tab and go to "Custom Properties" at the bottom. There is a field caled "FileNameColumnName." For the value, put the name of what column you want to store the file name in. Then, the that field will be available for your destination.
http://sqlblog.com/blogs/jamie_thomson/archive/2010/03/31/filenamecolumnname-property-flat-file-source-adapter-ssis-nugget.aspx

How to import a fixed width flat file into database using SSIS?

Does any one have a tutorial on how to import a fixed width flat file into a database using an SSIS package?
I have a flat file containing columns with varying lengths.
Column name Width
----------- -----
First name 25
Last name 25
Id 9
Date 8
How do I convert a flat file into columns?
Here is a sample package created using SSIS 2008 R2 that explains how to import a flat file into a database table.
Create a fixed-width flat file named Fixed_Width_File.txt with data as shown in the screenshot. The screenshot uses Notepad++ to display the file contents. It has the capability to show the special characters like carriage return and line feed. CR LF denotes the row delimiters Carriage return and Line feed.
In the SQL server database, create a table named dbo.FlatFile using the create script provided under SQL Scripts section.
Create a new SSIS package and add a new OLE DB Connection manager that would connect to the SQL Server database. Let's assume that the OLE DB Connection manager is named as SQLServer.
On the package's control flow tab, place a Data Flow Task.
Double-click on the data flow task and you will be taken to the data flow tab. On the data flow tab, place a Flat File Source. Double-click on the flat file source and the Flat File Source Editor will appear. Click the New button to open the Flat File Connection Manager Editor.
On the General section of the Flat File Source Editor, enter a value in Connection manager name (say Source) and browse to the flat file location and select the file. This example uses the sample file in the path C:\temp\Fixed_Width_File.txt If you have header rows in your file, you can enter a value 1 in the Header rows to skip textbox to skip the header row.
Click on the Columns section. Change the font according to your choice I chose Courier New so I could see more data with less scrolling. Enter the value 69 in the Row width text box. This value is the sum of width of all your columns + 2 for the row delimiter. Once you have set the correct row width, you should see the fixed width file data correctly on the Source data columns section. Now, you have to click at the appropriate locations to determine the column limits. Note the sections 4, 5, 6 and in the below screenshot.
Click on the Advanced section. You will notice 5 columns created for you automatically based on the column limits that we set on the Columns section in the previous step. The fifth column is for row delimiter.
Rename the column names as FirstName, LastName, Id, Date and RowDelimiter
By default, the columns will be set with DataType string [DT_STR]. If we are fairly certain, that a certain column will be of different data type, we can configure it in the Advanced section. We will change Id column to be of data type four-byte signed integer [DT_I4] and Date column to be of data type date [DT_DATE]
Click on the Preview section. The data will be shown as per the column configuration.
Click OK on the Flat file connection manager editor and the flat file connection will be assigned to the Flat File Source in the data flow task.
On the Flat File Source Editor, click on the Columns section. You will notice the columns that were configured in the flat file connection manager. Uncheck the RowDelimiter because we won't need that.
On the data flow task, place an OLE DB Destination. Connect the output from the Flat file source to the OLE DB Destination.
On the OLE DB Destination Editor, select the OLE DB Connection manager named SQLServer and set the Name of the table or the view drop down to [dbo].[FlatFile]
On the OLE DB Destination Editor, click on the Mappings section. Since the column names in the flat file connection manager are same as the columns in the database, the mapping will take place automatically. If the names are different, you have to manually map the columns. Click OK.
Now the package is ready. Execute the package to load the fixed-width flat file data into the database.
If you query the table dbo.FlatFile in the database, you will notice the flat file data imported into the database.
This sample should give you an idea about how to import fixed-width flat file into database. It doesn't explain how to handle error logging but this should get you started and help you discover other SSIS related features when you play with packages.
Hope that helps.
SQL Scripts:
CREATE TABLE [dbo].[FlatFile](
[Id] [int] NOT NULL,
[FirstName] [varchar](25) NOT NULL,
[LastName] [varchar](25) NOT NULL,
[Date] [datetime] NOT NULL
)
In the derived column transformation you can use SUBSTRING() function for each of the column.
Example:
Columns DerivedColumn
FirstName SUBSTRING(Data, startFrom, Length);
Here the FirstName has width 25 so if we consider that from the 0th position then in the derived column you should specify it by giving SUBSTRING(Data, 0, 25);
Similarly for other columns.
Very well explained, Siva! Your tutorial and excellent illustrations point out what Microsoft should have made clear
that the width for a fixed length row has to include the Carriage Return and Line Feed (CR & LF) characters (which I figured out because the preview showed the rows were not lining up correctly)
the all important step of defining an extra column to contain those CR & LF characters, even though they won't be imported. I figured this out, too. I would have benefited by finding your answer before I began.
Without those two things, an attempt to run the import will give this error message:
The data conversion for column "Column x" returned status value 4 and status text "Text was truncated or one or more characters had no match in the target code page.".
I have added in this error text in hopes someone will find this page while searching for the cause of their error. Your turorial is worth finding, even if after the fact!

how to load extracted file name into sql server table in SSIS

i have 3 csv files in a folder which contains eid, ename, country fields, and my 5 csv files names are test1_20120116_034512, test1_20120116_035512,test1_20120116_035812 etc.. my requirement is I want to take lastest file based on timne stamp and modified date, which i have done. Now i want to import the extracted file name into destination table..
my destination tables contains fields like,
filepath, filename, eid, ename, country
I have posted regarding this before in the same site i got an answer for extracting filename, now i want to load the extracted FileName into destination table
Import most recent csv file to sql server in ssis
my destination tables should have output as
C:/source test1_20120116_035812 1234 tester USA
In your DataFlow task, add a Derived Column Transformation. The value of CurrentFile will be the fully qualified path to the file. As you only want the file name, I would look to use a replace function on that with the base folder and then strip the remaining slash. This does not strip the file extension but you can add yet another call to REPLACE and substitute an empty string
Derived Column Name: filename
Derived Column:
Expression: REPLACE(REPLACE(#[User::CurrentFile], #[User::RootFolder], ""), "\\", "")
The above expects it to look like
CurrentFile = "C:\source\test1_20120116_035812.csv"
RootFolder = "C:\source"
Edit
I believe you've done something in your approach that I did not do. You should see a warning about possible truncation but given the values discussed in this and the preceding question, I don't believe the 4k limit on expressions will be of concern.
Displaying the derived column
Demonstrating the derived column does work
I will give you a +1 for providing an approach I wasn't aware of, but you'll still need to add a derived column to match your provided format (base path name)
Full path is provided from the custom properties. Use the above REPLACE section to remove the path info except use the column [FileName] instead of #[User::CurrentFile]
I tried to get the filename through the procedure which Billinkc has given, but its throwing me error stating that filename column failed becaue of truncation error..
Any how i tried different approach to load file name into table.
steps i have used
1. right click on flat file Source and click on show advanced edito for Flat file
2. select component Properties tab
3. Inside that Custom Properties section ---> it has a property FileNameColumnName
I have assigned Filename to that column property like
FileNameColumnName----> FileName thats it, am able to get the filename into my destination table..

Docmd.TransferText question

b'h
i will be programmatically importing a text file into a table. i have saved the import steps. i will use this:
DoCmd.TransferText(TransferType, SpecificationName, TableName, FileName, HasFieldNames, HTMLTableName, CodePage)
to do the import.
this is what SpecificationName means:
Specification Name The specification name for the set of options that determines how a text file is imported, exported, or linked. For a fixed-width text file, you must either specify a specification name or use a schema.ini file, which should be stored in the same directory as the imported, linked, or exported text file.
i do need a specific specification; however i do not know how to specify one. when i manually imported a table, i did save the specifications for my import, however i do not know how to call this in the TransferText.
does anyone know how to specify SpecificationName ?
When you do the import manually, you can save the import options as a specification. You assign a name to the specification at the time you create it. In Access 2003, click the Advanced button on the Import Text Wizard. Then you will get a dialog for <filename> Import Specification; click the Save As button and assign a Specification Name ... for example "MySpec".
Use that name (in quotes) as the SpecificationName option for your DoCmd.TransferText command.