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 2008 Forums
 Transact-SQL (2008)
 How to get record in one row

Author  Topic 

hardikspider123
Starting Member

12 Posts

Posted - 2014-05-13 : 15:56:44

Page S 745 NEW NULL
Page S 748 NULL PREVIOUS
jetter N 757 NULL PREVIOUS
jetter Y 757 NEW NULL
jetter Y 766 NULL PREVIOUS
jetter N 766 NEW NULL
Page Y 766 NEW NULL

Hi As per this scenario I need New and previous value from last two column I need in one row. first column is unique which is label which has multiple index like 745,748... but lablel name would be unique.so how would I get new and previous vale in one row using lable and index relationship?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-05-13 : 20:39:20
what is the expected result looks like ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

hardikspider123
Starting Member

12 Posts

Posted - 2014-05-13 : 22:04:38
Posted - 05/13/2014 : 15:56:44

Page S 745 NEW
Page S 748 Previoud
jetter N 757 NEw. PREVIOUS
jetter Y 766. New. PREVIOUS
Page Y 766 NEW

It should show this result. Check the index numbers and compare them you will find difference. Check 766 it will give you clear idea.jetter is same for same index and it should show new and previous as one record. But if it is page it shud take weathere it's previous or new . Either can be null and not null. Please let me know if it's not clear.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-05-13 : 22:32:59
use GROUP BY & MAX()

example


SELECT col1, col2, MAX(col3), MAX(col4)
FROM TABLE
GROUP BY col1, col2



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -