"Roji. P. Thomas" <lazydragon@nowhere.com> wrote in message
news:#$EcQIS$DHA.2808@TK2MSFTNGP10.phx.gbl...
> Tibor,
>
> I believe the query u suggested will not work.
>
> The expression
> EXISTS
> (SELECT TOP 3 * FROM tblname AS i
> WHERE o.pk = i.pk
> ORDER BY DateCreated DESC)
>
> Will evaluate to TRUE even if you have only one record.
> Right?
>
>
>
> --
> Roji. P. Thomas
> SQL Server Programmer
> "Tibor Karaszi" <tibor_please.no.email_karaszi@hotmail.nomail.com> wrote
in
> message news:exBzq7R$DHA.3712@tk2msftngp13.phx.gbl...
> > Then you can do something like below inside your trigger (code not
tested
> > because no DDL):
> >
> > DELETE FROM tblname AS o
> > WHERE NOT EXISTS
> > (SELECT TOP 3 * FROM tblname AS i
> > WHERE o.pk = i.pk
> > ORDER BY DateCreated DESC)
> >
> > Or use an IN instead.
> >
> > --
> > Tibor Karaszi, SQL Server MVP
> > Archive at:
> >
>
http://groups.google.com/groups?oi=djq&as_ugroup=microsoft.public.sqlserver > >
> >
> > "SamIAm" <samuel@rubbachicken.com> wrote in message
> > news:ehp0x4R$DHA.1464@tk2msftngp13.phx.gbl...
> > > I have a DateCreated column
> > >
> > > "Tibor Karaszi" <tibor_please.no.email_karaszi@hotmail.nomail.com>
wrote
> > in
> > > message news:OZlGPzR$DHA.1796@TK2MSFTNGP12.phx.gbl...
> > > > Do you have some column which specify the sequence of rows inserted
or
> > > date
> > > > when rows were inserted?
> > > >
> > > > --
> > > > Tibor Karaszi, SQL Server MVP
> > > > Archive at:
> > > >
> > >
> >
>
http://groups.google.com/groups?oi=djq&as_ugroup=microsoft.public.sqlserver > > > >
> > > >
> > > > "SamIAm" <samuel@rubbachicken.com> wrote in message
> > > > news:eySxXmR$DHA.3188@TK2MSFTNGP09.phx.gbl...
> > > > > Hi
> > > > >
> > > > > I have a system where each member can only have 3 records in a
> table.
> > > When
> > > > a
> > > > > new row is created for a member, I need to delete the oldest
record
> > > first
> > > > so
> > > > > that there are never more than 3 records for a member.
> > > > >
> > > > > How do I do this in TSQL?
> > > > >
> > > > > Thank,
> > > > >
> > > > > S
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>