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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Query Help...Get the results on the same line

Author  Topic 

callawayx14
Yak Posting Veteran

73 Posts

Posted - 2008-12-17 : 13:11:08
Hello! I could really use some help with this one. My table looks like this

tblTest

CODE | TYPE | OLD | NEW | REQUEST_ID
1 | Outbound | NULL | NULL | 123456
2 | Inbound | ABC123 | MNB876 | NULL
3 | Recreat | NULL | NULL | 123456

I'm trying to display the result of my query like this. There will only be three records (at most) for each Request_ID.

OLD | NEW | REQUEST_ID
ABC123 | MNB876 | 123456

Thanks for any help

hanbingl
Aged Yak Warrior

652 Posts

Posted - 2008-12-17 : 13:24:49
can you specify your business rule a little more?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-17 : 13:32:36
[code]SELECT MAX(OLD),MAX(NEW),REQUEST_ID
FROM Table
GROUP BY REQUEST_ID[/code]
Go to Top of Page

callawayx14
Yak Posting Veteran

73 Posts

Posted - 2008-12-17 : 13:36:48
Yes, Thank you. Each Request_ID can only have three records identified by the Code field (1-3). the row with Code '1' will always contain the Request ID. The row with Code '2' will always contain the NEW 'ID' . The row with Code '3' doesn;t always exist. I have no use for the row with Code '3'

I displayed the data in the table incorrectly the first tiem the OLD column is the one field that each record will have in common. I've displayed the correct version of the table below

CODE | TYPE | OLD_ID | NEW_ID | REQUEST_ID
1 | Outbound | ABC123 | NULL | 123456
2 | Inbound | ABC123 | MNB876 | NULL
3 | Recreat | ABC123 | NULL | 123456

OLD_ID | NEW_ID | REQUEST_ID
ABC123 | MNB876 | 123456
Go to Top of Page

hanbingl
Aged Yak Warrior

652 Posts

Posted - 2008-12-17 : 14:36:20
[code]select max(OLD_ID),max(NEW_ID),max(request_ID) from Request
group by old_ID[/code]
Go to Top of Page

callawayx14
Yak Posting Veteran

73 Posts

Posted - 2008-12-17 : 16:51:34
Thank you very much for tyour help!!
Go to Top of Page
   

- Advertisement -