Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to select an single rows to multiple columns


How to select an single rows to multiple columns

Author
Message
ramanathan.raman88
ramanathan.raman88
SSC-Enthusiastic
SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)SSC-Enthusiastic (102 reputation)

Group: General Forum Members
Points: 102 Visits: 42
I am Ramanathan and working in SQL SERVER 2008….Please help me
Table1
Location--Field
A1
A2
A3
B1
B2
B3
How to change an below format from table1
A B--Field
A1 B1
A2 B2
A3 B3
anthony.green
anthony.green
SSCertifiable
SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)

Group: General Forum Members
Points: 6102 Visits: 6078

declare @tab table (col1 char(2))
insert into @tab values
('A1'),
('A2'),
('A3'),
('B1'),
('B2'),
('B3')

SELECT
A.Col1,
B.Col1
FROM
(
SELECT
ROW_NUMBER() OVER(PARTITION BY LEFT(Col1,1) ORDER BY Col1) AS RowNum,
Col1
FROM
@tab
WHERE
LEFT(Col1,1) = 'A'
) AS A
FULL OUTER JOIN
(
SELECT
ROW_NUMBER() OVER(PARTITION BY LEFT(Col1,1) ORDER BY Col1) AS RowNum,
Col1
FROM
@tab
WHERE
LEFT(Col1,1) = 'B'
) AS B
ON
A.RowNum = B.RowNum





Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
When a question, really isn't a question - Jeff Smith
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search