I have imported some data from Excel file into my SQL Server table using SSIS. As because it's a report of profit & loss statement it has a header named as Trading Name, address fiscal year etc.
In SSIS, I've used OLE DB Source and used the query like
Select * from [Sheet1$A10:E]
so the data has been picked up. But U need to insert the trading Name and fiscal year information along with the others data like
Trader FYear AccNo AccName July August September
a 2014 4-0000 In
a 2014 4-0500 Ad $4,514.06 $4,521.23 $4,296.62
a 2014 4-1000 Me $37,085.78 $35,676.20 $36,150.87
a 2014 4-1300 Ro $11,876.20 $10,956.70 $11,819.04
a 2014 4-2000 Gr $57,540.76 $52,978.63 $54,272.24
I can pick up the trader and FYear from that Excel sheet by using OLE DB Source and SQL is
select * from [Sheet1$a1:a8]
and using conditional split I can separate them. But I don't actually know how to insert that data to each column of that table like above.
One more thing, if i write the query like
insert into tblA(Trader, FYear, AccNo, AccName, July, August, September)
select
'a', '2014', tblB.AccNo, tblB.AccName,
tblB.July, tblB.August, tblB.September;
then, it works in SQL Server table but could anyone help me to insert those two columns with that data like above table? Thanks anyway
![enter image description here][1]
Trading Name(a)
Address1
Address2
Profit & Loss Statement
Fiscal Year(2014)
AccNo AccName July August September
4-0000 In
4-0500 Ad $4,514.06 $4,521.23 $4,296.62
4-1000 Me $37,085.78 $35,676.20 $36,150.87
4-1300 Ro $11,876.20 $10,956.70 $11,819.04
4-2000 Gr $57,540.76 $52,978.63 $54,272.24
4-3500 B $0.00 $0.00 $0.00
4-4000 P $3,576.76 $4,110.66 $2,208.31
4-5000 Be $19,559.94 $17,926.14 $18,260.71
4-6000 Tu $13,471.97 $15,042.04 $13,150.06
4-8900 Re $3,500.00 $0.00 $0.00
Total Income $151,125.47 $141,211.60 $140,157.85
5-0000 Cost of Sales
Gross Profit $151,125.47 $141,211.60 $140,157.85
6-0000 Expenses
6-1000 General & Administrative Exp
6-1050 Accounting Fees $0.00 $0.00 $270.00
6-1200 Bank Charges $11.20 $11.20 $14.99
i can pick up the trader and FYear from that excel sheet by using OLE DB Source but i don't actually know how to insert that data to each column of that table like above
Use your existing method to populate two SSIS variables with the trader and FYYear at the start. Then subsequently in your data flow use a derived column transform and insert the variable value in as an additional column.
Based on the image you sent:
Delete everything except the first ForEachLoop container and its contents
Inside this ForEachLoop container add an execute SQL task which runs select * from [Sheet1$a1:a1]
. This should get the Fiscal Year (if it's in that cell) and you should be able to load that result into a single string variable (which you need to create beforehand). You need to set it up as ResultSet=SingleRow and you need to map the resultset area. You do not need to use the parameter mapping area
See here more more info on how to load a variable from a single row result: https://www.simple-talk.com/sql/ssis/ssis-basics-using-the-execute-sql-task-to-generate-result-sets/
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments