tags:

views:

45

answers:

4

Hi I want to delete all posts in a table exept the one where big_image has a value?

I have tryed allmost everything but its not working! This is tha last one:

sql3="delete from links where userId="& session("user_id") &" 
and big_image NOT IN (select big_image 
from links 
where userId = "& session("user_id") &" and big_image="& bgbild &");"

I would really appriciate some help, thanks. Claes

A: 

delete from links where userId="& session("user_id") &" and isnull(big_image,'') = ''

Bob Palmer
On a side note - change the inline SQL to a parameterized stored procedure or you are ripe for injection attacks ;)
Bob Palmer
Thank you all for your help, its working now, remember the 11te comand, you shall not program when tired ;-)
Claes Gustavsson
+4  A: 
DELETE FROM Links WHERE UserID = :UserID AND Big_Image IS NULL

And please parameterize your query or you may soon find yourself with no records in Links at all by way of SQL injection.

Larry Lustig
A: 

Maybe I'm overlooking something, but if you know the value of big_image you want to find (bgbild) couldn't you just use this?

sql3= "delete from links where userId="& session("user_id") &" 
 and big_image != " & bgbild
meagar
A: 

Hi guys I have tested with all of it and I cant get it working :-)

Now I have :

sql3="delete from links where userId="& userIdet &" and big_image IS NOT NULL;"

and instead of deleting all the other posts, it deletes the one with the image the second time I click on the button?

Claes Gustavsson
Oops — That should say IS NULL, with "not" removed.
Larry Lustig
Jepp, I removed it when I had posted this, and now it works!
Claes Gustavsson