August 27, 2009 at 1:16 am
Hi Everybody,
I am having a query and not able to solve it, Please help me in this.
There is a table as below. In the below table the column(A,B,C,D) values are either 0 or 1 or 2 only
ID A B C D
101A 1 0 1 2
102A 2 2 2 2
103A 1 0 1 1
104A 1 0 2 2
the requirement is , after executing the Query the columns are to be ID,0,1,2 and under the columns 0 the result is number of 0's occurs in the row where ID=101A,ID=102A,ID=103A,ID=104A. Likewise same for the remaining columns. The resulting table is as follows
ID 0 1 2
101A 1 2 1
102A 0 0 3
103A 1 3 0
104A 1 1 2
Please help me in this.
Thank you all,
Venu Gopal.K
Software Engineer
INDIA
August 27, 2009 at 2:53 am
Hi,
If I have understood the question correctly then you could use a PIVOT function to acheive this.
http://msdn.microsoft.com/en-us/library/ms177410.aspx
Hope this helps.
August 27, 2009 at 3:11 am
You could also do it this way (see attachment), may be a bit simpler if you've not done PIVOTS before.
There is probably a better way of doing it, but off the top of my head this is what I came up with.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply