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 |
|
axapta
Starting Member
11 Posts |
Posted - 2006-06-30 : 07:23:56
|
| Hi Group,I have 2 sets of 'matched' records in a table with a start date field of type datetime. I want to update a field called flag in the table with 1 for the earlier date and 2 for the later date.exampleStart Date Flag12/07/2006 117/07/2006 2regards |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-06-30 : 07:48:44
|
| update tblset flag = case when dte = (select max(t2.dte) from tbl t2 where t1.fld = t2.fld) then 2 else 1 endfrom tbl t1where fld is the match field for the pairs.==========================================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. |
 |
|
|
axapta
Starting Member
11 Posts |
Posted - 2006-06-30 : 11:18:39
|
nr does this update BOTH records? I do not have access to the system at the moment but looking at the syntax it looks like it's just one record thats being updated.quote: Originally posted by nr update tblset flag = case when dte = (select max(t2.dte) from tbl t2 where t1.fld = t2.fld) then 2 else 1 endfrom tbl t1where fld is the match field for the pairs.==========================================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.
|
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-07-01 : 23:25:07
|
| It'll update all rows on the table.==========================================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. |
 |
|
|
|
|
|