Link to home
Start Free TrialLog in
Avatar of NeoAshura
NeoAshuraFlag for United Kingdom of Great Britain and Northern Ireland

asked on

CSV to new database and exsisting database

Hi All,

I asked this in a previous question but never been able to figure it out.. i thought i had but it didnt work..

How do i define a new database and an exsisiting database inside of the same loop if im exporting about 100 CSV files...

These would need to be copied to the "New database" created dynamicllly by the loop (which i dont know how to do)

and to the exisisting one which i do know how to do.

Any Help would be appricated.

Many thanks

James
Avatar of Ephraim Wangoya
Ephraim Wangoya
Flag of United States of America image

Are you talking about database (exsisiting database inside of the same loop) or tables
Avatar of NeoAshura

ASKER

Hi ewangoya, thanks for the reply im talking about an exsisting database table inside the same loop.

so it dynamiclly creates one first, and then adds to an exsisting database also (like a backup i suppose) many thanks.

James
Hello,
Your question is not really clear? do you wanna CREATE a database using SSIS and name it using a variable / parameter mapping.  and set that part of your looping over the CSV files?

You can use "Excute SQL task" in the control flow   or  "OLE DB COMMAND"  inside the data flow-see attached

and the command should be    'Create Database @DatabaseName'


OR


declare @myName nvarchar(50)

declare @myCreate nvarchar(100)

SET @myName = 'Dbname'

Set @myCreate = 'Create Database ' + @mydate


execute sp_executesql @mycreate
Hi huslayer thanks for the reply.. I can see any attached files?

what i wanted to do was To Create a Database to add the data too.... But also add the data to an exsisitng file.


So the data goes to The one being created.

And

the one already set up.

Thanks James
That's easy, the hardest part is using the variables to create a dynamic name for the new DB, use a multicast to insert into 2 DBs

see attached.

please hit me again if you need more help and give me more details :)
a.jpg
put all of that into a for each loop container
b.jpg
heehee, I've put extension CVS instead of CSV !! lol
sorry to be a royal pain in the arse here huslayer,

But im still confused as to where your code goes inside the loop or inside the ole db command or inside the multicast? could you screen shot where it goes? and ill award you the points. it must be said this is by far the most help ive had from someone regarding SSIS so i am truly grateful for your time
Heeheee, you're welcome, I'm so happy to hear that :)
Anyway....let me give you more detailed steps..

let me ask you think, the DBs that you'll create, what name will you use for it?

also what about the tables inside that databases? how will you create it?

Database name would be something like New_JamesDatabase

and the table names something like New_Customers and New_details.

The tables would be created from the excel CSV file..

The CSV comes in and needs to go to 2 Databases One Already present "JamesDatabase located on localhost for testing purposes" and Also for it to create a new Database called New_JamesDatabase also on local host... If this is not possible then Just createing New tables inside of the same Database would also be useful.

Many thanks for your help again.

James
download this ZIP file, it contains the whole files you need

the password for the SSIS package is   -->    123

I assume that the files are in c:\test\   you may change that and the connection strings.

all the connections are pointing to localhost, integrated security

feel free to ask me for any clarifications.
there is one question why cant i edit anything on it? is it protected or something? if so how do i take it off?
yep the password for the SSIS package is   -->    123 User generated image
One last question and the points are all yours or i can open a new question up to you...

I now know how to make two database with one set of data but what if i had one set of data and wanted to create two tables in the same database with the same data?

I.e

DB_James

But with

Table_James
Table_James_New

Also how do u create the split in the multicast? sorry im really new to this and trying to learn

James
worked out the split in the multicast but still unsure about multiple tables.

James
ASKER CERTIFIED SOLUTION
Avatar of Jason Yousef
Jason Yousef
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks you have been most helpful, deffinatly the most help ive got. I will award you the points. Many thanks. im sure ill have more questions but will do a new question so u get more points :) Thanks again.. p.s do you have facebook or something and ill add you to update you on questions im stuck with or an email address?

Thanks James
Very helpful expert, Clear and quick to repsond. 10/10
thank you so much for the grade, points and the nice words, that's really what keeps me helpping more people and motivating :)

yes you can shot me an e-mail at     huslayer@hotmail.com

also i've started a SQL blog, maybe you can be my first follower :)

http://asqlb.blogspot.com/


Thank you again James and I'm ready to help you anytime with your questions

Jason