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, September 19, 2013 4:30 AM
Points: 78, 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

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


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 4:22 AM
Points: 5,073, Visits: 11,849
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.

When you ask a question (and please do ask a question: "My T-SQL does not work" just doesn't cut it), please provide enough information for us to understand its context.
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, September 19, 2013 4:30 AM
Points: 78, 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.
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, September 19, 2013 4:30 AM
Points: 78, 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.
Post #1388386
Posted Sunday, November 25, 2012 5:15 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 4:22 AM
Points: 5,073, Visits: 11,849
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.

When you ask a question (and please do ask a question: "My T-SQL does not work" just doesn't cut it), please provide enough information for us to understand its context.
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, September 19, 2013 4:30 AM
Points: 78, 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
Post #1388388
Posted Sunday, November 25, 2012 5:23 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 4:22 AM
Points: 5,073, Visits: 11,849
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.

When you ask a question (and please do ask a question: "My T-SQL does not work" just doesn't cut it), please provide enough information for us to understand its context.
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, September 19, 2013 4:30 AM
Points: 78, 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.
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, September 19, 2013 4:30 AM
Points: 78, Visits: 195
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, September 19, 2013 4:30 AM
Points: 78, Visits: 195
waiting for your valuable input guys........
Post #1388727
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse