Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

In sql i want to display data in the below format

AccountNo Remarks Month
Q49457 Abandoned 10
Q49457 Abandoned 11
Q49457 Locked-2 9
Q49458 Locked 11
Q49458 Abandoned 10


Required Output

AccountNo 11 Month Remarks 10 Month Remarks 9 Month Remarks
Q49457 Abandoned Abandoned Locked-2
Q49458 Locked Abandoned

What I have tried:

Hi, In sql i want to display data in the below format

Required Output

AccountNo 11 Month Remarks 10 Month Remarks 9 Month Remarks
Q49457 Abandoned Abandoned Locked-2
Posted
Updated 12-Dec-17 21:38pm

CREATE TABLE #TEMP(AccountNo varchar(50), Remarks varchar(50),Months int);
	 
  INSERT INTO  #TEMP  
               VALUES ('Q49457','Abandoned',10),
                      ('Q49457','Abandoned',11),
                      ('Q49457','Locked-2',	9),
                      ('Q49458','Locked',11),
                      ('Q49458','Abandoned',10);
  
SELECT  AccountNo,[11] AS Month11,[10] AS Month10 ,[9] AS Month9
FROM #TEMP
PIVOT(MAX(Remarks) FOR Months in( [11],[10],[9]))AS t1;  

--------------------------------------
AccountNo  Month11   Month10	Month9
----------------------------------------
Q49457	 Abandoned  Abandoned	Locked-2
Q49458	 Locked	    Abandoned	NULL
 
Share this answer
 
v2
As your question is posted, this will do the job for you:-

SELECT 'AccountNo 11 Month Remarks 10 Month Remarks 9 Month Remarks Q49457 Abandoned Abandoned Locked-2'

Now I realise that's not the answer you wanted to get. But I don't know the answer you do want to get.
Read your question back to yourself. Do you think you've stated the problem clearly and provided enough information?

Next time, take more care over your question - you may get better replies than this one.
 
Share this answer
 
Hello Krishnaraosan..

I understand your concern, but you haven't mentioned what was the query you've used to get the output you mentioned in the end.

There could be some intersection of query result executions that made you get that result.

Please mention the query to resolve.

Regards,
Mansi
 
Share this answer
 
Comments
krishnaraosan 13-Dec-17 2:06am    
I have not used any query i am expecting query from you
pt1401 13-Dec-17 2:35am    
Also, please tabulate the data in your question properly.
If it's easy to read, people will be more likely to offer solutions.
pt1401 13-Dec-17 2:37am    
Re. "I am expecting query from you".
That's not going to happen without telling us how the data is stored - what's the database schema? Tables? Columns?
krishnaraosan 13-Dec-17 2:41am    
In table i have rows

AccountNo Remarks Month
Q49457 Abandoned 10
Q49457 Abandoned 11
Q49457 Locked-2 9
Q49458 Locked 11
Q49458 Abandoned 10

Now i want Output based on accountno month wise as below

AccountNo 11 Month 10 Month Remarks 9 Month Remarks
Q49457 Abandoned Abandoned Locked-2
Q49458 Locked Abandoned
Santosh kumar Pithani 13-Dec-17 3:18am    
Let me know what is this ->"AccountNo 11 Month 10 Month Remarks 9 Month Remarks"

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