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 |
|
gad
Starting Member
14 Posts |
Posted - 2006-01-30 : 21:34:24
|
| I have the following table and I'm trying to identify sessionid's where the category names in one searchcriteriaid group have changed within in the same session. In the example below, Land, Multifamily, Retail, Shopping Center are all consistent until the last searchcriteriaid group (60720021), so this sessionid should return. Thanks for any suggestions. SearchCriteriaid SessionID Category60719347 55850633 Land60719347 55850633 Multifamily60719347 55850633 Retail60719347 55850633 Shopping Center60719548 55850633 Land60719548 55850633 Multifamily60719548 55850633 Retail60719548 55850633 Shopping Center60719625 55850633 Land60719625 55850633 Multifamily60719625 55850633 Retail60719625 55850633 Shopping Center60719717 55850633 Land60719717 55850633 Multifamily60719717 55850633 Retail60719717 55850633 Shopping Center60719719 55850633 Land60719719 55850633 Multifamily60719719 55850633 Retail60719719 55850633 Shopping Center60719788 55850633 Land60719788 55850633 Multifamily60719788 55850633 Retail60719788 55850633 Shopping Center60720021 55850633 Land60720021 55850633 Multifamily60720021 55850633 Industrial60720021 55850633 Office |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-01-30 : 23:07:55
|
| select SearchCriteriaidfrom tbl t1where Category not in (select t2.Category from tbl t2 where t2.SearchCriteriaid = (select min(t3.SearchCriteriaid) from tbl t3 where t2.SessionID = t1.SessionID))==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
gad
Starting Member
14 Posts |
Posted - 2006-01-31 : 20:08:19
|
| Previous suggestion worked well (thanks a lot), but only when there was a distinct sesssionid, my full set of data has many differnt sessionids - how would I accomodate for that? Thanks. searchcriteriaid sessionid category60658874 55756828 Land60658874 55756828 Multifamily60658961 55756828 Land60658961 55756828 Multifamily58040575 51478216 Office58040576 51478216 Retail |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-01-31 : 21:23:13
|
| oopsselect SearchCriteriaidfrom tbl t1where Category not in (select t2.Category from tbl t2 where t2.SearchCriteriaid = (select min(t3.SearchCriteriaid) from tbl t3 where t3.SessionID = t1.SessionID))==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
gad
Starting Member
14 Posts |
Posted - 2006-02-02 : 16:06:57
|
| Brilliant - thanks nr - much appreciated. |
 |
|
|
|
|
|