SunQuest
           MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old May 10th, 2004, 10:52 PM
Tazz13 Tazz13 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 12 Tazz13 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Need some help with DELETE command

Hello,

I am new to SQL and am learning basics in a class.

I am having a problem with deleting. I have this table that looks like (only a small portion shown):

letter lDate
a 1/1/98
a 1/1/98
a 1/1/98
a 1/1/99
a 1/1/99
b 1/1/99
c 1/1/97
d 1/1/99

I want to delete all letter a with dates before 1/1/99. Could someone please help me out?...I can't seem to get this to work.

Thank you,

Tazz

Reply With Quote
  #2  
Old May 10th, 2004, 11:56 PM
Username=NULL Username=NULL is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: TX
Posts: 249 Username=NULL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 7 h 6 m 42 sec
Reputation Power: 5
Send a message via Yahoo to Username=NULL
Here's how to code a DELETE
Code:
Delete  from [myTable]
where   [filter criteria]

...not to hard, but be careful. B/c they can be somewhat disasterous, I'd advise pre SELECTing what you want to delete first, just to be sure you're whacking the correct data. Just do a normal query to get what you're looking for then just change the Select * to Delete. Honestly, test this code, I'm not familiar w/dates in that format, @some pont these should select the records you're looking for...
Code:
--1)
select  * from myTable
where   letter = 'A'
and     lDate < '1/1/99'

--or 2) since you want everything before Jan 1st, 1999

select  * from myTable
where   letter = 'A'
and     YEAR(lDate) < '99' --may need to use '1999'

...then simply Delete 'em.

Last edited by Username=NULL : May 11th, 2004 at 12:02 AM.

Reply With Quote
  #3  
Old May 11th, 2004, 12:17 AM
Tazz13 Tazz13 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 12 Tazz13 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thank you very much, It worked with the 1999.

Thankz again,

Tazz

Reply With Quote
  #4  
Old May 11th, 2004, 02:08 AM
Username=NULL Username=NULL is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: TX
Posts: 249 Username=NULL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 7 h 6 m 42 sec
Reputation Power: 5
Send a message via Yahoo to Username=NULL
sure Tazz, anytime.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Need some help with DELETE command


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway