I created a transaction procedure and it all works except for some reason the rollback keeps displaying its error message and it is not allowing the insert to function properly. So now I am unsure of what I need to do to fix this when I comment out the section it all works perfectly it is only the IF rollback statement
Create Proc DP_Transaction @PartNumber Varchar (10)= NULL, @PartDescription Varchar(50) = Null, @ReorderLevel Decimal(5,0) =Null, @StockLevel decimal(5,0)= null, @StockOnOrder decimal(5,0) =null as If @PartNumber IS NULL begin Print 'You must enter something for Partnumber' Print 'Order Not Processed' print ' ' return end If @PartDescription IS NULL begin Print 'You must enter something PartDescription' Print 'Order Not Processed' print ' ' return end If @ReorderLevel IS NULL begin Print 'A number must entered for ReorderLevel' Print 'Order Not Processed' print ' ' return end If @StockLevel is Null Begin print 'A number must be entered for StockLevel' print 'Order Not Processed' Print '' Return End If @StockOnOrder is null Begin Print 'A number must be entered for StockOnOrder' Print 'Order Not Processed' Print '' Return End Begin Transaction Insert into InventoryPart (Partnumber,PartDescription,ReorderLevel,StockLevel,StockOnOrder) Values(@PartNumber,@PartDescription,@ReorderLevel, @StockLevel, @StockOnOrder) //This is where I am having the errors If exists (Select PartNumber from InventoryPart where PartNumber = @PartNumber) Begin Print ' The Partnumber ' + @PartNumber+' is already in the InventoryPart table' print ' you must select a different PartNumber' Print ' Item not inserted' print '' Rollback end else begin Commit Transaction print 'Part has been added' print '' print '' End