July 9, 2009 at 1:23 pm
July 9, 2009 at 1:24 pm
Try changing
a.ballotcommitteename b. ballotcommitteename
to
a.ballotcommitteename < b. ballotcommitteename
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537
July 9, 2009 at 2:02 pm
Thanks Guys.
Hey Mark I changed what you told me and it worked so far. However the problem is I don't know how many time's I'll have to add the column values to the roll.

Some users can have only one value, some two values, some three, and so on.
Damn this is hard
July 9, 2009 at 2:18 pm
Something like this then
WITH CTE AS (
SELECT pa_contactidname,asmemberof,ballotcommitteename,
ROW_NUMBER() OVER(PARTITION BY pa_contactidname,asmemberof ORDER BY ballotcommitteename) AS rn
FROM user_table)
SELECT pa_contactidname,asmemberof,
MAX(CASE WHEN rn=1 THEN ballotcommitteename END) AS ballotcommitteename1,
MAX(CASE WHEN rn=2 THEN ballotcommitteename END) AS ballotcommitteename2,
MAX(CASE WHEN rn=3 THEN ballotcommitteename END) AS ballotcommitteename3
FROM CTE
GROUP BY pa_contactidname,asmemberof
If you don't know the maximum number of ballotcommitteename in advance, you'll have
to construct the query dynamically
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537
July 9, 2009 at 2:38 pm
You are the man. It worked however I do need to do it dynamically because I don't know the maximum number of ballotcommitteename in advance.
CTE is way new to me.
July 19, 2009 at 9:57 pm
http://www.sqlservercentral.com/articles/cross+tab/65048/
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply