Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
with the command bulk insert I now want to place this line and column of this information. Thank you....

Before :

title2 title3
Name Default Web Site
State Stopped
PSComputerName s07
RunspaceId c62cf173-af1f-46bd-a57f-3b29e74998ed
After :

Default Web Site Stopped s07 c62cf173-af1f-46bd-a57f-3b29e74998ed

What I have tried:

--create table for importing data
create table DataImpTest
(
Title1 varchar(100),
Title2 varchar(1000)
)

--do the bulk insert
BULK INSERT DataImpTest  
   FROM '<File Path>\DataImp.csv'  
   WITH  
     (  
        FIELDTERMINATOR =' ',  
        ROWTERMINATOR = '\n',
		FIRSTROW=2
      );  

--check the imported data
	  SELECT * FROM DataImpTest

-- fix the unequal spacing in Title2 column
	  UPDATE DataImpTest
	  SET Title2 = LTRIM(RTRIM(Title2))

--check the trimmed data
	  SELECT * FROM DataImpTest

	  --pivoting the data to columns
	  SELECT *
	  FROM DataImpTest AS t
	  PIVOT(MAX(Title2) FOR Title1 IN ([Name],[State],[PSComputerName],[RunspaceId]))p


/*
Output
---------------------------------------
Name	                State  PSComputerName	RunspaceId
-----------------------------------------------------------------------------
Default Web Site	Stopped	s07	c62cf173-af1f-46bd-a57f-3b29e74998ed
Posted
Updated 25-Aug-18 20:04pm
v2
Comments
David_Wimbley 26-Aug-18 0:59am    
I may be missing something but i dont see a difference between your before and after examples. Unless your saying the data is in a column and you want to insert it as a row (that part isnt clear).
Member 12632819 26-Aug-18 1:24am    
Yes, we want to replace the row and column of such data with Pivot I do not know what
aggregation function in sql server
Member 12632819 26-Aug-18 2:05am    
This problem solves me. The only problem that comes with the data is the data I have on my table with a lot of data.

Name : Faraaaaaaa
State : Stopped
PSComputerName : s07
RunspaceId : c62cf173-af1f-46bd-a57f-3b29e74998ed

Name : FaraGostarvvvvv
State : Stopped
PSComputerName : s07
RunspaceId : c62cf173-af1f-46bd-a57f-3b29e74998ed

Name : FaraGostarMultiSitePublisher
State : Stopped
PSComputerName : s07
RunspaceId : c62cf173-af1f-46bd-a57f-3b29e74998ed

Name : FaraGostarMudddd
State : Stopped
PSComputerName : s07
RunspaceId : c62cf173-af1f-46bd-a57f-3b29e74998ed

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900