Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can it is possible to do this in single select statement.


for Example

SQL
CREATE TABLE dbo.Table1 
(
    Col1        CHAR(1),
    Col2        CHAR(1),
    Col3        CHAR(1),
    Col4        VARCHAR(50)
)
GO


INSERT INTO dbo.Table1 VALUES ('A','B','C','100,28784,3'),('C','D','E','200,30,400,8999')
GO

SELECT * FROM dbo.Table1;
GO

Output should like this...It should be in single select statement.

SQL
Col1 Col2 Col3 Val1  VAl2   Val3  Val4  Val5
A    B     C    100  28784  3     null  null
C    D     E    200  30     400   8999  null
Posted
Updated 4-Mar-13 23:14pm
v2
Comments
Shanalal Kasim 5-Mar-13 5:16am    
Val1 VAl2 Val3 Val4 Val5 - these columns are fixed?
Davidduraisamy 5-Mar-13 5:17am    
No..this can extend according to Delimiter.
Shanalal Kasim 5-Mar-13 5:21am    
k
Davidduraisamy 5-Mar-13 6:38am    
Have you found the answer...

1 solution

You need to split text of col3 into many columns. Here you'll find a solution: http://blog.sqlauthority.com/2010/02/10/sqlauthority-news-converting-a-delimited-string-of-values-into-columns/[^]
 
Share this answer
 

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