Query on Dates

Query on Dates

Post by Pete » Fri, 13 Feb 2004 11:06:09



i have 10 records in a table

Field1 varchar(10)   NOT NULL
Field2 varchar(10)   NOT NULL
Field3 smalldatetime  NOT NULL

how can i delete the record with the oldest date ?

 
 
 

Query on Dates

Post by Roji. P. Thoma » Fri, 13 Feb 2004 11:14:49


Try

CREATE TAble #tblDemo
(Field1 varchar(10)   NOT NULL,
Field2 varchar(10)   NOT NULL,
Field3 smalldatetime  NOT NULL)

INSERT INTO #tblDemo
VALUES('ABC','XYZ','02/01/2004')

INSERT INTO #tblDemo
VALUES('ABC','XYZ','02/02/2004')

INSERT INTO #tblDemo
VALUES('ABC','XYZ','02/03/2004')

INSERT INTO #tblDemo
VALUES('ABC','XYZ','02/04/2004')

SELECT * FROM #tblDemo

DELETE FROM #tblDemo
WHERE Field3 = (SELECT Min(Field3)
FROM #tblDemo)

SELECT * FROM #tblDemo

DROP TABLE #tblDemo

--
Roji. P. Thomas
SQL Server Programmer

Quote:> i have 10 records in a table

> Field1 varchar(10)   NOT NULL
> Field2 varchar(10)   NOT NULL
> Field3 smalldatetime  NOT NULL

> how can i delete the record with the oldest date ?


 
 
 

Query on Dates

Post by rahul nagarma » Fri, 13 Feb 2004 14:26:10


hi,

delete tblname
where dt_colname in (select min(dt_colname)
from tblname )

thx
rahul nagarmat
sql server mvp
intel corp.

 
 
 

1. Query for Date when there's no date field

Hello,
Thanks for all of the previous help. Now I have another
issue.

I have a query that I need to run weekly, which will show
how many users, have joined each week. I can extract the
needed data except for the time/date that they joined.
The confusion that I am having is this....

The db has no created date field, so what type of syntax
would I write to find out when the data(new user) was
inputted, so it falls within the week indicated.

I only have read privileges to the db.

Thanks so much
Dave

2. Price of D3 product in the world

3. Query between dates (smalldatetime)

4. Mistake SQL

5. Update Query with date value

6. Looking for Customer/Bug tracking database for Unix

7. Querying with Dates

8. US-VA: oakton-Oracle DBA

9. Query Using Dates

10. Query By date

11. query by date problem

12. query involving dates

13. Query by date/account