Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 2 table category and module. category table has 2 fields id & category module has 3 fields.id,modulename & catid

category table has 2 fields :

id & category

module has 3 fields:

id,modulename & catid

category
id         |        category
-----------------------------
1          |         ABC
2          |         PQR


module
id   catid      modulename
--------------------------
1   1              A 
2   1              B
3   2              Q
4   2              P


I want to convert row to column and I'm getting a result like below:
ABC     |    PQR    
-------------------
A       |    NULL  
B       |    NULL  
NULL    |    Q
NULL    |    P


and I want result like below (without null values)

ABC      |     PQR    
-------------------
A        |      Q
B        |      P


this is my query

SQL
SELECT * FROM ( SELECT CASE WHEN category='ABC' THEN modulename ELSE '' END AS 'ABC', CASE WHEN category='PQR' THEN modulename ELSE '' END AS 'PQR' FROM category c INNER JOIN module m ON m.catid=c.id )t  

but from this query i had null values, can u tell me how to avoid this null value?
Posted
Updated 24-Jul-13 3:06am
v5
Comments
Misha india 24-Jul-13 8:57am    
content moved to the question - Maciej Los
ZurdoDev 24-Jul-13 9:07am    
You are wanting to combine values from different rows. I am not sure how you would do that.
Misha india 24-Jul-13 9:16am    
Listen , I m having two table 1. Category and 2nd module .
now i want module and category name in one query and the result should be like
category name as column dynamicfrom query and Module name as row data

Like

category1 category2
-----------------------
module1 module3
module2 module4

1 solution

 
Share this answer
 
v2
Comments
gvprabu 24-Jul-13 10:54am    
hi frnd,

hru?....
Maciej Los 24-Jul-13 11:18am    
Thank you, i'm fine ;)
And how are you?
gvprabu 24-Jul-13 11:54am    
I am doing good.. :-)

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