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 |
|
fredong
Yak Posting Veteran
80 Posts |
Posted - 2006-07-13 : 15:44:57
|
| I have 3 tables named RBL, s_RAB, RAB that I need to get the s_RABID.TAGID and RAB.TAGID values that has the MAX s_RAB.ChangedDate that is smaller than the RBL.ChangedDate and has s_RABID.TAGID <> RAB.TAGID. Below is my example. Please advise. Thanks.s_RAB Table-----------RABID TAGID ChangedDate1111 0011 01/01/061111 0033 01/02/06 --> I need to get this value1111 0066 01/04/06 RAB Table-----------RABID TAGID ChangedDate1111 0044 01/03/06 --> and this value1112 0033 01/05/06 RBL Table-----------RABID ChangedDate 1111 01/03/061112 01/05/06 Below is my script and I am not getting any value back.SELECT s_RAB.RABID, RBL.ItemType, s_RAB.ChangedDate, s_RAB.TAGID, RAB.TAGIDFROM RBL, s_RAB, RABWHERE s_RAB.RABID = RBL. RABID AND s_RAB.RABID = RAB.RABID AND s_RAB.ChangedDate IN (SELECT MAX(s_RAB.ChangedDate) FROM s_RAB WHERE s_RAB.RABID = RBL.RABID) AND s_RAB.ChangedDate < RBL.BALChangedDate AND s_RAB.TAGID <> RAB.TAGID AND RBL.ItemType ='R'k |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-07-13 : 16:32:03
|
| You are missing the ItemType in your table definitions. Also you have renamed changeddate to balchangeddate in the query.With the expected sample data above, what is your complete expected output?Peter LarssonHelsingborg, Sweden |
 |
|
|
fredong
Yak Posting Veteran
80 Posts |
Posted - 2006-07-13 : 18:50:33
|
| itemtype is in the table I forgot to add on it and they are all itemtype 'R'k |
 |
|
|
|
|
|