|
|
|
SSC 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
|
|
|
|
|
SSCarpal 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.
|
|
|
|
|
SSC 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.
|
|
|
|
|
SSC 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.
|
|
|
|
|
SSCarpal 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.
|
|
|
|
|
SSC 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
|
|
|
|
|
SSCarpal 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.
|
|
|
|
|
SSC 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.
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Thursday, March 21, 2013 2:14 AM
Points: 77,
Visits: 184
|
|
| Any suggestion on this.......
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Thursday, March 21, 2013 2:14 AM
Points: 77,
Visits: 184
|
|
| waiting for your valuable input guys........
|
|
|
|