MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

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:
  #1  
Old October 16th, 2003, 08:15 PM
xsoftdev xsoftdev is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Los Angeles, CA
Posts: 64 xsoftdev User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 51 m 7 sec
Reputation Power: 10
SQL Delete multiple records

Hello folks,

I trying to delete multiple records at once from a Table called 'Favorites' with 2 criterias but it does not seem to work. Only one record gets deleted.

I have a form where users can select from a check box which records to delete. I want to delete ALL the records that the user has selected.

This is the Stored procedure I am using in Access 2000.

DELETE Favorites.UserID, Favorites.FavID
FROM Favorites
WHERE (((Favorites.UserID)=[@usserid]) AND ((Favorites.FavID)=[@favid]));


Can anyone help me correct this statement to delete all the FavID items for this user. I am thinking some kind of loop is needed but that would make the DB very busy...

Reply With Quote
  #2  
Old October 16th, 2003, 09:35 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,375 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 7 h 30 m 16 sec
Reputation Power: 4140
DELETE will only delete rows

it appears that you want to delete column values?

note that DELETE does not take a column list

your statement should be

DELETE FROM tablename WHERE...

the WHERE clause will indicate which rows

make sense?

rudy
http://r937.com/

Reply With Quote
  #3  
Old October 16th, 2003, 09:53 PM
xsoftdev xsoftdev is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Los Angeles, CA
Posts: 64 xsoftdev User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 51 m 7 sec
Reputation Power: 10
FavoriteID UserID FavID
1 2 6
2 4 8
3 4 9
4 6 5

Above is my table, FavoriteID is auto number.

I am trying to delete rows 2 & 3 in one statement. This userID, 4 has 2 items in the Favorites and he has selected to delete both items.

Hope this is more clear than my earlier post.

Rudy, I am not sure what you mean by delete column values

Thanks for your help.

Reply With Quote
  #4  
Old October 16th, 2003, 10:14 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,375 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 7 h 30 m 16 sec
Reputation Power: 4140
DELETE FROM Favorites
WHERE UserID=4 AND FavID IN (8,9)

Reply With Quote
  #5  
Old October 16th, 2003, 10:44 PM
xsoftdev xsoftdev is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Los Angeles, CA
Posts: 64 xsoftdev User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 51 m 7 sec
Reputation Power: 10


Thanks for your help Rudy!

Got it working, however I can't get the Stored procedure in Access to work:

DELETE Favorites.FavID, Favorites.UserID
FROM Favorites
WHERE (((Favorites.FavID) In ([@favid])) AND ((Favorites.UserID)=[@userid]));


But for now I just wrote the SQL statement in ASP and is working.

Thanks again!

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > SQL Delete multiple records

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap