I have written a stored procedure for duplicate item for vendor the output i need from this SP is whenever for a vendor we will raise purchase order the system should check that their shouldn't be any po in the system for the same item by the selected vendor. Its working fine when only one item is selected but it is behaving wrongly when more than one item is selected.
If (@object_type='22' and @transaction_type='A')
Declare @Vend as varchar(200)
Declare @ItemCode as varchar(200)
Select @Vend =CardCode From OPOR Where DocEntry = @list_of_cols_val_tab_del
Select @ItemCode=ItemCode From POR1 Where DocEntry=@list_of_cols_val_tab_del
IF 1 !=(Select Count(T0.DocEntry) From OPOR T0 Inner Join POR1 T1 On T0.DocEntry=T1.DocEntry Where T0.CardCode=@Vend and T1.ItemCode=@ItemCode)
select @error =1
select @error_message = 'Item Code Already Exists For This Vendor'