I want a stored procedure to create a temptable based on 2 columns of table_A
, and then check if there are rows in table_B
(with 5 columns) that have these 2 columns like the way they are in table_A
. Don't do anything to them a delete rows that are not duplicate.
Something like this:
Create Procedure DeleteExtra
as
Create Table #TempTotalHoney
(
HarvestDate Date,
HoneyType VarChar(50)
)
INSERT INTO #TempTotalHoney
Select HarvestDate, HoneyType
From tHoneyHarvest
Group BY HarvestDate, HoneyType
//until here temptable created as I want, but I don't know how to check
//not duplicated rows, I tried this But it is wrong...
Delete From tHoneyWeight
Where HarvestDate AND HoneyType Not in (select HarvestDate, HoneyType
From #TempTotalHoney)
//must check these tow columns together not separately
If(OBJECT_ID('tempdb..#TempTotalHoney') Is Not Null)
Begin
Drop Table #TempTotalHoney
End
This is the error I get:
Msg 4145, Level 15, State 1, Procedure DeleteExtra, Line 17
An expression of non-boolean type specified in a context where a condition is expected, near 'AND'.
Update:
this is #TempTotalHoney that created from table_A
HarvestDate HoneyType
---------------------------------------------------
2017-01-10 Pure
2017-01-10 Semi-Pure
2017-02-03 Pure
2017-02-04 artificial
and
table_B:
RecID HarvestDate HoneyType TotalCombs TotalWeight
----------------------------------------------------------------
1 2017-01-10 Pure 10 22
3 2017-01-10 Semi-Pure 11 24
4 2017-02-03 Pure 22 50
6 2017-02-04 artificial 25 56
8 2017-01-10 Semi-Art 10 18.5
9 2017-02-05 Pure 11 19
I want the RecID 8 and 9 that combination of HarvestDate And HoneyType of them not exists in #TempTotalHoney be deleted.