Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Pivot Table?

Author  Topic 

abenitez77
Yak Posting Veteran

53 Posts

Posted - 2012-01-30 : 12:43:20
How can i get my table to show the results i want below? Pivot table? I've never used pivot before.

Table:
tocid prop_id str_val num_val
1059786 104 USD NULL
1059786 105 Pricing Null
1059786 108 NULL 1539.17


results:
tocid str_val str_val num_val
1059786 USD Pricing 1539.17

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-30 : 12:46:24
you need to GROUP BY tocid

SELECT tocid,
MAX(CASE WHEN prop_id = 104 THEN str_val END) AS str_val1,
MAX(CASE WHEN prop_id = 105 THEN str_val END) AS str_val2,
MAX(CASE WHEN prop_id = 108 THEN num_val END) AS num_val
FROM table
GROUP BY tocid


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -