Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete the first 3 rows of a table

Status
Not open for further replies.

Dom71555

IS-IT--Management
Feb 6, 2005
47
US
I am trying to delete the first 3 records in a table but am at a loss as how to do it.

Table looks like this...
create table #classCuts (
lastname varchar(50),
firstname varchar(50),
studentnumber varchar(15),
coursenumber varchar(13),
sectionnumber int,
coursename varchar(30),
periodname varchar(10),
teacherdisplay varchar(30),
cutdate smalldatetime

If a student cuts a class more than 3 times, I want to remove the first 3 records, yet keep the other records so teachers can write a referral. Data would look like this in the table..
xxx Joseph 6519 103 10 ENGLISH 10 8 Mr. Teacher 10/28/2009
xxx Joseph 6519 103 10 ENGLISH 10 8 Mr. Teacher 11/4/2009
xxx Joseph 6519 103 10 ENGLISH 10 8 Mr. Teacher 11/13/2009
xxx Joseph 6519 103 10 ENGLISH 10 8 Mr. Teacher 11/17/2009

The end result will leave only 1 record in the table. The first 3 deleted.
I tried a cursor to do this but am stuck with the syntax.
 
Anyway, assuming select produces the correct result, change it to
Code:
select T.* into #TempToRemove from ...

update T set DeleteField = 1 from myTable T inner join #TempToRemove R on T.ID = R.ID

drop table #TempToRemove


PluralSight Learning Library
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top