Merging Data from four excel files into a single database file - database

I have 4 excel files and I wanted to insert the data from these 4 excel files to a single database file in MSSQL.
1st Excel file - 10 rows
2nd Excel file - 20 rows
3rd Excel file - 30 rows
4th Excel file - 40 rows
The table in MSSQL should have 100 rows after the task. Thw column names are similar in all the files.
I have taken
tfileInputExcel1 -> tMap -> tMSSQLOutput
tfileInputExcel2
tfileInputExcel3
tfileInputExcel4
All mapped to the same tMap.
I just don´t know how to Map different input sources to a single tMap. I have been searching on the internet on this but I haven¨t find any relevant for my need. Can anyone here help me out on how to map tMap to a multiple input and output sources.

Try this way:
tFileList (with the appropriate file mask)-tFileInputExcel-tMap-tMSSqlOutput
or if you want just one interaction with the database:
tFileList (with the appropriate file mask)-tFileInputExcel-tMap-tHashOutput
onSubJobOk
tHashInput-tMSSqlOutput
Note the tMap is necessary only if you have to transform the input data

Related

How to read a flat file and load it into 2 different SQL tables(different table structure) using SSIS 2019

I have a flat file which doesn't have the header record. The data except the trailing record is like a fixed width flat file with no delimiters.
Data in flat file looks like:
TOM ROLLS
DAVECHILLS
TOTAL2XYZ
Fixed Width data(first 2 lines as shown in the above flat file data)
ColumnName Start position End position
Name 1 4
Last_name 5 9
I want to load the data(till trailing record) in data_table and the trailing record(starting with Total) in another table. The data in the total table should look like
c1 c2
2 XYZ
For the data table, I am currently using "fixed width" and dividing the data into different column and it is working fine. Can you please help to load this last trailing record in a different table(Total table as discussed above)
You have not provided enough data for me to test because I can find several methods to load one row and accomplish what you are asking but those methods not necessarily work with multiple rows depending on the structure of you source data.
On the surface it appears that you simply need to make another flat file connection and define the starting and end position to extract only the data for the second table.

Copy & Paste Errors When Moving Data From SSMS to Excel

I'm attempting to copy a query result from SSMS to excel. I selected "copy with headers" and pasted it into Excel. My data set has 9 columns. When I paste the data into excel, information from column 9 ends spread across columns 9, 10 and 1 It looks like this:
A B C D E F G H I -Column Heading
A B C D E F G H I I -Data
I
(blank row)
I've reviewed the query results in SSMS and this is not occurring in the original data. When the value in column F is NULL the additional row and information in column 10 do not occur. Thus far I have tried the following:
-When I remove column 9 from the query then copy & paste, column 8 is spread across 8, 9, and 1.
-I've also created a brand new spreadsheet, made sure to clear any formatting and tried the copy & paste.
-I saved the query results as a .csv file and imported it into Excel. I still got the same result.
-I copied the columns individually one at a time. The the information in the 8th column ends up on two lines paired with the other columns of the next row. So each item in column 8 becomes another row offset downwards until there are many more values in column 8 than other columns. Where the value in column 8 is NULL, this does not occur.
-I removed all the other items from the query result so that only the values of columns 8 and 9 are returned. All information from column 9 ends up in column 8 followed by a blank row.
Returning 8 alone, each item returned ends up on two rows.
Returning 9 alone, the data is pasted correctly.
The headers are always in the right place. From what I can surmise, the data in column 8 is the culprit here. The data type is a varchar(max) which allows nulls. The information included is in the following format,
(TC Date & Time, Last Name, First Name) Comments
Moving SSMS query results into Excel to make tables is something I do frequently. However I have never before encountered this result. Hopefully my explanation is thorough enough so someone can tell me how to correct this error. Thanks!
Replace feed and Carriage returns from your dataset before you can paste into Excel, Try something like this on the columns you are having issues and then try to paste it in excel:
SELECT REPLACE(REPLACE(yourcolumnname, CHAR(13),' '), CHAR(10),' ')
FROM table
This is probably due to using 'Text to columns' recently in Excel. That splits columns using some rule. Columns need to be set back to 'tab delimited'.
For the offending column:
Data → Text to Columns
Original Data Type: Check Delimited
Click Next
Delimiters: check 'Tab', uncheck anything else.
Click Next
Click Finish
SSMS copy-paste does not preserve data types. Excel tries to parse the string and splits it into additional columns or even lines.
I develop SSMSBoost add-in and we have covered this in our video, which explains 3 different ways of exporting the data into Excel without data loss (data type information is preserved): (Copy-Paste in native excel format, XML export, .dqy Query) https://youtu.be/waDCukeXeLU

Rows concatenating while copying data from SQL to Excel

My SQL query returns 100 rows. When I copy the result to excel sheet or try to download as CSV, data in one of the columns is getting concatenated and excel shows only 30 rows.
For example my query result shows:
Id Name Expression
1 aa One
2 bb Two
3 cc Three
4 dd Four
The data in excel sheet gets copied as:
Id Name Expression
1 aa One
3 cc Two Three Four
Any help is welcome!
Right click any database on your SQL Server -> Tasks -> Export Data, a wizard will pop up. Select your source SQL Server and Destination as Flat File Destination, you can just put an empty csv file on your drive, select Format, Text qualifier. follow with the wizard. See what you can get.
Since I found out that the problem was created by double quotes, I just separated the rows with double quotes.
So we can separate rows, that is first pick all rows with no quotes and then pick all rows with quotes
or
replace quotes with something else.
Select Id, Name, Case Expression When '"' THEN 'BuggerQuotes' ELSE Expression FROM table1
After copying data to excel sheet, I replaced my BuggerQuotes text with double quotes.

Auto-create folders from excel file

I want to create about 1000 folder, but I think the best way isn't "Create new folder - rename it". I have a excel file (.xls) with a column full with the preferable names..
eg
names.xls
column 1 = name1, name2, name3 , name4 ,name5 , name6 etc
column 2 = amount1 , amount2, amount 3, amount 4. etc
So I want a folder with a name test, and inside it I want all the folders with the names of column 1.. Is it possible and how that think can be done? I think the best language for this job is C, or not? Is excel file a problem? May I insert the 1st column from xls file to an txt file?
The fastest way to do this might be to this:
Insert a column before column 1 with the command to create a directory (md)
Fill it downwards for all the rows with values in the name column (now the 2nd column)
Copy the two columns to a textfile
Search and remove whitespaces if needed
Save the textfile as .bat or .cmd and execute it in the correct directory
If this is a one time thing writing a program could be overkill, but if you need to do it often go with VBS as suggested above.

Import a text file by converting repeating groups of lines into columns

My data file looks like
1234567 7654321
TEXT ABOUT STUFF
ON MULTIPLE LINES
NOT SURE HOW MANY
1234567 7654321
TEXT ABOUT STUFF
ON MULTIPLE LINES
NOT SURE HOW MANY
The only thing for certain is a new record starts with 2 sets of numbers that are 7 characters long. The numbers are also on a new line and appear as my sample data above.
I am using SQL Server Express on Windows 8.
Ultimately I need the first group of numbers in a column, 2nd group in another column and the remainder of the text in the 3rd column.
This is the realm of ETL. The SQL Server was of doing this is to use SSIS.

Resources