I am creating a transaction procedure. I am having a syntax error at the first if statement it says 'expecting variable' everything else is working fine not sure why it is having trouble.\here is the code
Create Proc DP_Test4Transaction
@ReorderLevel Decimal(5,0) =Null,
@StockLevel decimal(5,0)= null,
@StockOnOrder decimal(5,0) =null
as
Declare @PartDescription Varchar (10)= NULL,
//Here is where i am getting the error
If @ReorderLevel IS NULL
begin
Print 'You must enter a number 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 'Customer not inserted'
Print ''
Return
End
Begin Transaction
Insert into InventoryPart
(PartDescription,ReorderLevel,StockLevel,StockOnOrder)
Values(@PartDescription,@ReorderLevel, @StockLevel, @StockOnOrder)
Select @PartDescription = (Select Partdescription From InventoryPart
Where @PartDescription = PartDescription)
If exists (Select PartDescription from InventoryPart where Partdescription = @PartDescription)
Begin
Print ' The PartDescription'+ @PartDescription+'is already in the database'
print ' you must select a different Partdescription'
Print ' Item not inserted'
print ''
Rollback
end
else
begin
Commit Transaction
print 'Part has been added'
print ''
print ''
End
you probably don't need the entire code but just in case I missed something somewhere
Looks like you have a erroneous comma after your declare statement that needs to be removed.
Declare @PartDescription Varchar (10)= NULL,