ahmed elbarbary

ahmed elbarbary

  • NA
  • 1.6k
  • 254.9k

How to delete from table in case code type have value or not

Jan 28 2020 1:04 PM
How to delete from table in case of code type have value ?
I have temp table #temppc
I need when codetype on temp table #tempPc not have null meaning have value
then
delete statement from table Parts.TradeCodes will be
  1. DELETE TCC FROM #TempPC t INNER JOIN Parts.TradeCodes TCC ON t.ZPLID=TCC.ZPLID and t.CodeType=TCC.codeType  
and if codetype on temp table #TempPc is null then delete statment from table Parts.TradeCodes will not have codetype
and it will be
  1. DELETE TCC FROM #TempPC t INNER JOIN Parts.TradeCodes TCC ON t.ZPLID=TCC.ZPLID  
so How to modify delete statment on query below that to delete based on two cases if codetype have value or not
  1. create table #TempPC  
  2. (  
  3. [ID] INT IDENTITY,  
  4. ZPLID INT,  
  5. CodeType int  
  6.   
  7. )  
  8.   
  9.   
  10.   
  11.   
  12. DELETE TCC FROM #TempPC t INNER JOIN Parts.TradeCodes TCC ON t.ZPLID=TCC.ZPLID  

Answers (2)