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.
| Author |
Topic |
|
Petronas
Posting Yak Master
134 Posts |
Posted - 2011-10-13 : 15:55:41
|
| Hi, I am new to SQL and I have the following script: select distinct(o.order_id),o.product_id, (CASE c.description WHEN 'Process Requests' THEN f.method END) [Process Requests],(CASE c.description WHEN 'Process Alerts' THEN f.method END) [Process Alerts] into #temp_afrom orders o with(nolock), product_mapping m with(nolock), f_method f with(nolock),category c with(nolock)where o.order_id = m.order_id andf.method_id = m.method_id andc.category_id = m.category_id ando.Order_ID = 12345order by order_id ascselect * from #temp_a(nolock)The output is order_id product_id Process requests Process Alerts12345 ABC NULL Mail12345 ABC Mail NULLThe required output is :order_id product_id Process requests Process Alerts12345 ABC Mail MailThanks in advance,Petronas |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2011-10-13 : 16:26:18
|
| Here's one way:(nolock is unnecessary on a #temp table)select order_id, product_id, max([process requests]) as [process Requests], max([process Alerts]) as [process alerts]from #temp_agroup by order_id, product_idBe One with the OptimizerTG |
 |
|
|
Petronas
Posting Yak Master
134 Posts |
Posted - 2011-10-13 : 16:45:10
|
| Thanks TJ! It worked perfectly. Appreciate your help!! |
 |
|
|
|
|
|