Hi micah,
Refer the below modified procedure. If there is any changes with your condition then modify as per your requirement.
SQL
CREATE TABLE FiveInchesMMORDERNkwereStore
(
UserID INT IDENTITY
,UserName NVARCHAR(100) PRIMARY KEY NOT NULL
,Phone NVARCHAR(100)
,Location NVARCHAR(50)
,Item NVARCHAR(100)
,Inches NVARCHAR(100)
,BlockCategory NVARCHAR(500)
,PaymentMethod NVARCHAR(500)
,OrderStatus NVARCHAR(500)
,Stock FLOAT
,QuantityOrdered FLOAT
,Discount MONEY
,UnitPrice MONEY
,OrderDate DATETIME
)
GO
INSERT INTO FiveInchesMMORDERNkwereStore VALUES('Micah','111111','south africa','Chai','1','1','NEFT','Completed',50,10,10,50,GETDATE())
GO
CREATE PROCEDURE [dbo].[InsertFiveInchesMMORDERNkwereSore]
@UserName nvarchar (100),
@Phone nvarchar (100),
@Location nvarchar (50),
@Item nvarchar (100),
@Inches nvarchar (100),
@BlockCategory nvarchar (500),
@PaymentMethod nvarchar (500),
@OrderStatus nvarchar(500),
@Stock float,
@QuantityOrdered float,
@Discount money,
@UnitPrice money,
@OrderDate datetime
AS
BEGIN
IF NOT EXISTS(SELECT UserName FROM FiveInchesMMORDERNkwereStore WHERE UserName = @UserName)
BEGIN
-- Insert
INSERT INTO FiveInchesMMORDERNkwereStore
(
[UserName]
,[Phone]
,[Location]
,[Item]
,[Inches]
,[BlockCategory]
,[PaymentMethod]
,[OrderStatus]
,[Stock]
,[QuantityOrdered]
,[Discount]
,[UnitPrice]
,[OrderDate]
)
VALUES
(
@UserName
,@Phone
,@Location
,@Item
,@Inches
,@BlockCategory
,@PaymentMethod
,@OrderStatus
,@Stock
,@QuantityOrdered
,@Discount
,@UnitPrice
,@OrderDate
)
END
ELSE
BEGIN
-- Update
UPDATE FiveInchesMMORDERNkwereStore
SET [Phone] = @Phone
,[Location] = @Location
,[Item] = @Item
,[Inches] = @Inches
,[BlockCategory] = @BlockCategory
,[PaymentMethod] = @PaymentMethod
,[OrderStatus] = @OrderStatus
,[Stock] = @Stock
,[QuantityOrdered] = @QuantityOrdered
,[Discount] = @Discount
,[UnitPrice] = @UnitPrice
,[OrderDate] = @OrderDate
WHERE [UserName] = @UserName
END
SELECT SCOPE_IDENTITY() AS UserID
END
Screenshot