954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Convert Column value to Row

Hi,

I want to convert Single Column values to Row.

Table Original Content:

Code Amount Expenditure
10027 5000.00 LOCAL CONVEYANCE
10027 320.00 LOCAL CONVEYANCE
10116 1589.00 TRAVEL EXPENSES
10095 350.00 LOCAL CONVEYANCE
10095 1215.00 TRAVEL EXPENSES

Expected Output :

Code LC TE
10027 5000.00 NULL
10027 320.00 NULL
10116 NULL 1589.00
10095 350.00 1215.00


Thanks in Advance

visweswaran28
Light Poster
35 posts since May 2010
Reputation Points: 10
Solved Threads: 0
 
adam_k
Practically a Posting Shark
804 posts since Jun 2011
Reputation Points: 256
Solved Threads: 149
 

If you had some way of grouping the rows (such as a date?) you could use a PIVOT construct. However, based on your example data, I don't see any relationship of how you could reasonably show both LC and TE. Here's what I mean...look at this scenario:

Code  Amount   Expenditure
10027 5000.00  LOCAL CONVEYANCE
10027  320.00  LOCAL CONVEYANCE
10027  100.00  TRAVEL EXPENSES  <----new example row added to your scenario
10116 1589.00  TRAVEL EXPENSES
10095  350.00  LOCAL CONVEYANCE
10095 1215.00  TRAVEL EXPENSES


Where would line 4 go? With line 2 or with line 3? The only thing I can think of is to do it programmatically rather than with straight SQL. More explanation is in order.

BitBlt
Master Poster
711 posts since Feb 2011
Reputation Points: 367
Solved Threads: 109
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You