We help IT Professionals succeed at work.

Query to delete data

algotube
algotube asked
on
Medium Priority
211 Views
Last Modified: 2012-05-12
Good day Experts;

   I have a table called dbo.CREW  with columns:

START_TIME        datetime
END_TIME             datetime
CREW                     varchar(255)
DIV_CREW            varchar(255)
COORDINATOR    text

I have a request to delete end_time > 2009/07/01

what would be the query to do this?
Comment
Watch Question

Database Administrator
CERTIFIED EXPERT
Commented:
Delete From dbo.CREW Where END_TIME > '2009/07/01'

I would verify the proper data is being deleted by doing a SELECT with the same criteria first.
Commented:
The below code will do what you asked.  WARNING: Typically people delete the older data.  The code below will delete recent data  I suspect taht you want to reverse the > sign to be <.


delete dbo.CREW
where end_time > '2009/07/01'
Chris MangusDatabase Administrator
CERTIFIED EXPERT

Commented:
@bhoeniq, you posted the exact same solution for the OP as I did.  How does this help the OP?

Commented:
cmangus, it was timing.  when I read the question you there was no answer.  Granted I did answer a little slow (I got side tracked) and didn't bother to refresh my screen before I submitted mine.  You can have the points, I don't care.  It's not like it's complicated code.  My real concern is that algotube is going to delete the wrong side of the date.  That is the real help that I'm providing.  I would hate to see him delete all of his current data, when he meant to delete the old data.

Algotube, if your > sign was right please give cmangus all the credit.  If it's wrong then give me the credit.
Chris MangusDatabase Administrator
CERTIFIED EXPERT

Commented:
No, it's not about credit.  I just wonder when I see so many posts on EE where duplicate answers are given several minutes apart.

I see your concern about the OP deleting the wrong data.  I often have to delete data on both sides of a time scale and didn't pay any attention to the direction they were going because I am used to it.
SAMIR BHOGAYTATeam Lead
CERTIFIED EXPERT

Commented:
hello,

delete from CREW
where end_time > '2009/07/01'

or

delete from CREW
where end_time > 2009/07/01
Chris MangusDatabase Administrator
CERTIFIED EXPERT

Commented:
@bhoeniq:  See what I mean?  :)  Now we have another poster who is posting the same solution an hour and a half later?

Commented:
I didn't realize it was this bad.  He definitely can't use my excuse of not refreshing the page.  At least it's worth a good laugh.

Author

Commented:
cmangus and  bhoenig thanks for the fast replies. You both provided areas that I should be checking before I go ahead and delete data.  So thank you very much appreciated.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.