Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 123»»»

Data Import from CSV file Expand / Collapse
Author
Message
Posted Sunday, November 25, 2012 4:17 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, March 21, 2013 2:14 AM
Points: 77, Visits: 184
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

Post #1388380
Posted Sunday, November 25, 2012 4:21 AM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 10:13 AM
Points: 4,227, Visits: 9,460
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:

http://www.sqlservercentral.com/articles/Best+Practices/61537/

If you are asking for help and your post does not contain a question, you should expect responses which do not contain any answers. Put a question mark in there somewhere - it's not rocket science.
Post #1388381
Posted Sunday, November 25, 2012 4:25 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, March 21, 2013 2:14 AM
Points: 77, Visits: 184
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.
Post #1388382
Posted Sunday, November 25, 2012 5:09 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, March 21, 2013 2:14 AM
Points: 77, Visits: 184
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.
Post #1388386
Posted Sunday, November 25, 2012 5:15 AM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 10:13 AM
Points: 4,227, Visits: 9,460
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:

http://www.sqlservercentral.com/articles/Best+Practices/61537/

If you are asking for help and your post does not contain a question, you should expect responses which do not contain any answers. Put a question mark in there somewhere - it's not rocket science.
Post #1388387
Posted Sunday, November 25, 2012 5:20 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, March 21, 2013 2:14 AM
Points: 77, Visits: 184
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
Post #1388388
Posted Sunday, November 25, 2012 5:23 AM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 10:13 AM
Points: 4,227, Visits: 9,460
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:

http://www.sqlservercentral.com/articles/Best+Practices/61537/

If you are asking for help and your post does not contain a question, you should expect responses which do not contain any answers. Put a question mark in there somewhere - it's not rocket science.
Post #1388389
Posted Sunday, November 25, 2012 5:27 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, March 21, 2013 2:14 AM
Points: 77, Visits: 184
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.
Post #1388390
Posted Sunday, November 25, 2012 8:40 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, March 21, 2013 2:14 AM
Points: 77, Visits: 184
Any suggestion on this.......
Post #1388405
Posted Monday, November 26, 2012 10:48 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, March 21, 2013 2:14 AM
Points: 77, Visits: 184
waiting for your valuable input guys........
Post #1388727
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse