SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Data Import from CSV file


Data Import from CSV file

Author
Message
rhythm.varshney
rhythm.varshney
SSC-Enthusiastic
SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)

Group: General Forum Members
Points: 140 Visits: 195
I have a CSV file which is having record like mentioned below.

UserName User Id Type

RamKumar ram MSAD
RamaC rama MSAD
RamesK rames MSAD
Rameshv ramesh MSAD
RamKumar ramp PCG
Ramig rami PCG
Ramem rame PCG
RampD ramp PCG
RampD rampX MSAD




Here I need to import this in a DB table for which DDL is like mentioned below

CREATE TABLE #USERTABLE([USERNAME] [varchar](100),[MSAD] [varchar](20),[PCG] [varchar](20))



I need to import the data into the table.The logic is If Type is MSAD then it should update MSAD column of table with userid and if type is PCG then it should update PCG column also there should not be duplicate entry for a uername i.e. for RamKumar ther should be only one entry. with both MSAD and PCG column values.

Expected output is mentioned below

UserName MSAD PCG

RamKumar ram ramp
RamaC rama
RamesK rames
Rameshv ramesh
Ramig rami
Ramem rame
RampD rampX ramp


Phil Parkin
Phil Parkin
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18227 Visits: 20393
So what is your question?


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
rhythm.varshney
rhythm.varshney
SSC-Enthusiastic
SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)

Group: General Forum Members
Points: 140 Visits: 195
Phil Parkin (11/25/2012)
So what is your question?


I need to import the data into the table.The logic is If Type is MSAD then it should update MSAD column of table with userid and if type is PCG then it should update PCG column also there should not be duplicate entry for a uername i.e. for RamKumar ther should be only one entry. with both MSAD and PCG column values.
rhythm.varshney
rhythm.varshney
SSC-Enthusiastic
SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)

Group: General Forum Members
Points: 140 Visits: 195
rhythm.varshney (11/25/2012)
Phil Parkin (11/25/2012)
So what is your question?


I need to import the data into the table.The logic is If Type is MSAD then it should update MSAD column of table with userid and if type is PCG then it should update PCG column also there should not be duplicate entry for a uername i.e. for RamKumar ther should be only one entry. with both MSAD and PCG column values.


I tried upinsert but it is not working for duplicate username.
Please provide your input.
Phil Parkin
Phil Parkin
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18227 Visits: 20393
rhythm.varshney (11/25/2012)
Phil Parkin (11/25/2012)
So what is your question?


I need to import the data into the table.The logic is If Type is MSAD then it should update MSAD column of table with userid and if type is PCG then it should update PCG column also there should not be duplicate entry for a uername i.e. for RamKumar ther should be only one entry. with both MSAD and PCG column values.


I am not seeing a UserId column.

Also, all you have done is stated your requirements. From these, you are assuming that I can guess what your question is, but I can't.


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
rhythm.varshney
rhythm.varshney
SSC-Enthusiastic
SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)

Group: General Forum Members
Points: 140 Visits: 195
Phil Parkin (11/25/2012)
rhythm.varshney (11/25/2012)
Phil Parkin (11/25/2012)
So what is your question?


I need to import the data into the table.The logic is If Type is MSAD then it should update MSAD column of table with userid and if type is PCG then it should update PCG column also there should not be duplicate entry for a uername i.e. for RamKumar ther should be only one entry. with both MSAD and PCG column values.


I am not seeing a UserId column.

Also, all you have done is stated your requirements. From these, you are assuming that I can guess what your question is, but I can't.


UserId column is in CSV file not in SQL table.
So if you see the first record(username is RamKumar) from CSV should insert userid value in MSAD column of table while 5th record with same username should update the same record with userid from CSV in PCG column of table
Phil Parkin
Phil Parkin
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18227 Visits: 20393
rhythm.varshney (11/25/2012)
Phil Parkin (11/25/2012)
rhythm.varshney (11/25/2012)
Phil Parkin (11/25/2012)
So what is your question?


I need to import the data into the table.The logic is If Type is MSAD then it should update MSAD column of table with userid and if type is PCG then it should update PCG column also there should not be duplicate entry for a uername i.e. for RamKumar ther should be only one entry. with both MSAD and PCG column values.


I am not seeing a UserId column.

Also, all you have done is stated your requirements. From these, you are assuming that I can guess what your question is, but I can't.


UserId column is in CSV file not in SQL table.


Ahh, I see - I saw 'User' and 'Id' separated by a space and assumed they were separate columns.


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
rhythm.varshney
rhythm.varshney
SSC-Enthusiastic
SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)

Group: General Forum Members
Points: 140 Visits: 195
Phil Parkin (11/25/2012)
rhythm.varshney (11/25/2012)
Phil Parkin (11/25/2012)
rhythm.varshney (11/25/2012)
Phil Parkin (11/25/2012)
So what is your question?


I need to import the data into the table.The logic is If Type is MSAD then it should update MSAD column of table with userid and if type is PCG then it should update PCG column also there should not be duplicate entry for a uername i.e. for RamKumar ther should be only one entry. with both MSAD and PCG column values.


I am not seeing a UserId column.

Also, all you have done is stated your requirements. From these, you are assuming that I can guess what your question is, but I can't.


UserId column is in CSV file not in SQL table.


Ahh, I see - I saw 'User' and 'Id' separated by a space and assumed they were separate columns.


Yes so I need first row of CSV should insert into table and the value for MSAD column will get the value of UserId of CSV and when again the 5th row will have same username it should update the same record of table by updating PCG column with userid of CSV.
rhythm.varshney
rhythm.varshney
SSC-Enthusiastic
SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)

Group: General Forum Members
Points: 140 Visits: 195
Any suggestion on this.......
rhythm.varshney
rhythm.varshney
SSC-Enthusiastic
SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)

Group: General Forum Members
Points: 140 Visits: 195
waiting for your valuable input guys........
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search