Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 409
  • Last Modified:

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
0
NeoAshura
Asked:
NeoAshura
  • 10
  • 9
1 Solution
 
Ephraim WangoyaCommented:
Are you talking about database (exsisiting database inside of the same loop) or tables
0
 
NeoAshuraAuthor Commented:
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
0
 
Jason Yousef, MSSr. BI DeveloperCommented:
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
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
NeoAshuraAuthor Commented:
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
0
 
Jason Yousef, MSSr. BI DeveloperCommented:
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
0
 
Jason Yousef, MSSr. BI DeveloperCommented:
put all of that into a for each loop container
b.jpg
0
 
Jason Yousef, MSSr. BI DeveloperCommented:
heehee, I've put extension CVS instead of CSV !! lol
0
 
NeoAshuraAuthor Commented:
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
0
 
Jason Yousef, MSSr. BI DeveloperCommented:
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?

0
 
NeoAshuraAuthor Commented:
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
0
 
Jason Yousef, MSSr. BI DeveloperCommented:
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.
0
 
NeoAshuraAuthor Commented:
there is one question why cant i edit anything on it? is it protected or something? if so how do i take it off?
0
 
Jason Yousef, MSSr. BI DeveloperCommented:
yep the password for the SSIS package is   -->    123 a
0
 
NeoAshuraAuthor Commented:
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
0
 
NeoAshuraAuthor Commented:
worked out the split in the multicast but still unsure about multiple tables.

James
0
 
Jason Yousef, MSSr. BI DeveloperCommented:
Well I really wouldn't copy into 2 tables or even 2 databases, if you care about performance.
at the end you can use another execute SQL task and copy an entire table to another table. instead of inserting into 2 tables.

 copy task code to copy table
0
 
NeoAshuraAuthor Commented:
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
0
 
NeoAshuraAuthor Commented:
Very helpful expert, Clear and quick to repsond. 10/10
0
 
Jason Yousef, MSSr. BI DeveloperCommented:
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
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 10
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now