Connecting Tech Pros Worldwide Forums | Help | Site Map

sql deletion with delimiters

Newbie
 
Join Date: Jun 2009
Posts: 3
#1: Jul 1 '09
Have a problem with deletion that contains delimiters:

tb2 & tb3 contains Dept like: GM/ACCT/FIN
Want to delete it such that Dept is not found in tb1 & tb2

This query will still delete even if is found in tb1 & tb2:

Expand|Select|Wrap|Line Numbers
  1. delete a from tb1 a left join tb2 b on b.Dept=a.Dept
  2. left join tb3 c on c.Dept=a.Dept
  3. where a.Dept=@dept and b.Dept is null and c.Dept is Null
  4.  

Member
 
Join Date: Dec 2007
Posts: 47
#2: Jul 1 '09

re: sql deletion with delimiters


Set null to Null as im not sure if it is case sensitive. Your variable should be in quotes also. Try this...

Expand|Select|Wrap|Line Numbers
  1. delete a from tb1 a left join tb2 b using(Dept)
  2. left join tb3 c using(Dept)
  3. where(a.Dept='@dept' and b.Dept is Null and c.Dept is Null )
Newbie
 
Join Date: Jun 2009
Posts: 3
#3: Jul 1 '09

re: sql deletion with delimiters


hi daniel2335,

this could not work as using is an incorrect syntax.

Still have problem with this query:
Quote:
tb2 & tb3 contains Dept like: GM/ACCT/FIN
Want to delete it such that Dept is not found in tb1 & tb2
Expand|Select|Wrap|Line Numbers
  1. Delete a from t1 a left join t2 b on b.FirstName LIKE '%a.FirstName%'
  2. left join t3 c on c.FirstName LIKE '%a.FirstName%'
  3. where a.FirstName LIKE '%GM%'
  4. and b.FirstName is null and c.FirstName is Null
  5.  
Member
 
Join Date: Dec 2007
Posts: 47
#4: Jul 1 '09

re: sql deletion with delimiters


I may be clutching at straws but it may have been because I didn't put a space after using. Does this work?

Expand|Select|Wrap|Line Numbers
  1. delete a from tb1 a left join tb2 b using (Dept) 
  2. left join tb3 c using (Dept) 
  3. where (a.Dept='@dept' and b.Dept is Null and c.Dept is Null ) 
Are you storing multiple departments in a single field? This is bad database design and is making it hard to get your data back. Google "mysql normalization tutorial"(more american links :P) They will show you how to better your database design.
Reply