ALTER PROCEDURE [dbo].[SP_ORDER_INSERT]
(
@COMPANYID INT,
@CUSTOMERID VARCHAR(50),
@PRODUCTID VARCHAR(100),
@QUANTITY INT,
@PRICE VARCHAR(200),
@PRODUCTPRICE VARCHAR(200),
-- @TOTALPRICE DECIMAL(18,2),
@TAX DECIMAL(18,2),
@SHIPPING DECIMAL(18,2),
@GRANDTOTAL DECIMAL(18,2),
@NOTES NTEXT,
@STATUS VARCHAR(10),
@ERRORMESSAGE VARCHAR(MAX),
@CREATEDBY VARCHAR(50),
@SHIPPINGCARRIER VARCHAR(50),
@TRACKINGNUMBER VARCHAR(50),
@PRODUCTCOLOR VARCHAR(MAX),
@PRODUCTSIZE VARCHAR(MAX),
@ORDERQTY VARCHAR(MAX)
)
AS
BEGIN
DECLARE @COUNTER AS INT
DECLARE @PID AS INT
DECLARE @PRC AS DECIMAL(18,2)
DECLARE @PCOLOR AS VARCHAR(50)
DECLARE @PSIZE AS VARCHAR(50)
DECLARE @Pqty AS VARCHAR(20)
BEGIN TRY
INSERT INTO [DBO].[ORDER]
( [COMPANYID],
[CUSTOMERID],
[QUANTITY],
[PRICE],
[TAX],
[SHIPPING],
[GRANDTOTAL],
[NOTES],
[CREATEDAT],
[UPDATEDAT],
[ErrorMessage],
[STATUS],
[SHIPPINGCARRIER],
[TRACKINGNUMBER]
)
VALUES
( @COMPANYID,
@CUSTOMERID,
@QUANTITY,
@PRICE,
@TAX,
@SHIPPING,
@GRANDTOTAL,
@NOTES,
GETDATE(),
'',
@ERRORMESSAGE,
@STATUS,
@SHIPPINGCARRIER,
@TRACKINGNUMBER
)
SELECT @COUNTER = [dbo].[FN_SPLIT_STRING](@PRODUCTID,',',0)------ this "FN_SPLIT_STRING" Function used --------------------------------------------------------------------------------to count the number data separated by comma
WHILE ( @COUNTER > 1) ---------------------------- While Loop Start
BEGIN
SET @COUNTER = @COUNTER - 1
SELECT @PID = [dbo].[FN_SPLIT_STRING](@PRODUCTID,',',@COUNTER)--- Fetch --------------------------The Data in @COUNTER Position in @PRODUCTID parameter
-- SELECT @PRC = [dbo].[FN_SPLIT_STRING](@PRICE,',',@COUNTER)
SELECT @PRC = [dbo].[FN_SPLIT_STRING](@PRODUCTPRICE,',',@COUNTER)
SELECT @PCOLOR = [dbo].[FN_SPLIT_STRING](@PRODUCTCOLOR,',',@COUNTER)
SELECT @PSIZE = [dbo].[FN_SPLIT_STRING](@PRODUCTSIZE,',',@COUNTER)
SELECT @Pqty = [dbo].[FN_SPLIT_STRING](@ORDERQTY,',',@COUNTER)
INSERT INTO [DBO].[PRODUCTORDER]
( [ORDERID],
[COMPANYID],
[PRODUCTID],
[QUANTITY],
[PRODUCTPRICE],
[ProductSize],
[ProductColor],
[CREATEDBY],
[CREATEDAT],
[UPDATEDBY],
[UPDATEDAT]
)
VALUES
( IDENT_CURRENT('ORDER'),
1,
@PID,
@Pqty,
@PRC,
@PSIZE,
@PCOLOR,
@CUSTOMERID,
GETDATE(),
'',
''
)
END
END TRY
BEGIN CATCH
END CATCH
BEGIN TRAN
IF XACT_STATE() =0
BEGIN
COMMIT TRAN
END
ELSE
BEGIN
ROLLBACK TRAN
END
END
(
@COMPANYID INT,
@CUSTOMERID VARCHAR(50),
@PRODUCTID VARCHAR(100),
@QUANTITY INT,
@PRICE VARCHAR(200),
@PRODUCTPRICE VARCHAR(200),
-- @TOTALPRICE DECIMAL(18,2),
@TAX DECIMAL(18,2),
@SHIPPING DECIMAL(18,2),
@GRANDTOTAL DECIMAL(18,2),
@NOTES NTEXT,
@STATUS VARCHAR(10),
@ERRORMESSAGE VARCHAR(MAX),
@CREATEDBY VARCHAR(50),
@SHIPPINGCARRIER VARCHAR(50),
@TRACKINGNUMBER VARCHAR(50),
@PRODUCTCOLOR VARCHAR(MAX),
@PRODUCTSIZE VARCHAR(MAX),
@ORDERQTY VARCHAR(MAX)
)
AS
BEGIN
DECLARE @COUNTER AS INT
DECLARE @PID AS INT
DECLARE @PRC AS DECIMAL(18,2)
DECLARE @PCOLOR AS VARCHAR(50)
DECLARE @PSIZE AS VARCHAR(50)
DECLARE @Pqty AS VARCHAR(20)
BEGIN TRY
INSERT INTO [DBO].[ORDER]
( [COMPANYID],
[CUSTOMERID],
[QUANTITY],
[PRICE],
[TAX],
[SHIPPING],
[GRANDTOTAL],
[NOTES],
[CREATEDAT],
[UPDATEDAT],
[ErrorMessage],
[STATUS],
[SHIPPINGCARRIER],
[TRACKINGNUMBER]
)
VALUES
( @COMPANYID,
@CUSTOMERID,
@QUANTITY,
@PRICE,
@TAX,
@SHIPPING,
@GRANDTOTAL,
@NOTES,
GETDATE(),
'',
@ERRORMESSAGE,
@STATUS,
@SHIPPINGCARRIER,
@TRACKINGNUMBER
)
SELECT @COUNTER = [dbo].[FN_SPLIT_STRING](@PRODUCTID,',',0)------ this "FN_SPLIT_STRING" Function used --------------------------------------------------------------------------------to count the number data separated by comma
WHILE ( @COUNTER > 1) ---------------------------- While Loop Start
BEGIN
SET @COUNTER = @COUNTER - 1
SELECT @PID = [dbo].[FN_SPLIT_STRING](@PRODUCTID,',',@COUNTER)--- Fetch --------------------------The Data in @COUNTER Position in @PRODUCTID parameter
-- SELECT @PRC = [dbo].[FN_SPLIT_STRING](@PRICE,',',@COUNTER)
SELECT @PRC = [dbo].[FN_SPLIT_STRING](@PRODUCTPRICE,',',@COUNTER)
SELECT @PCOLOR = [dbo].[FN_SPLIT_STRING](@PRODUCTCOLOR,',',@COUNTER)
SELECT @PSIZE = [dbo].[FN_SPLIT_STRING](@PRODUCTSIZE,',',@COUNTER)
SELECT @Pqty = [dbo].[FN_SPLIT_STRING](@ORDERQTY,',',@COUNTER)
INSERT INTO [DBO].[PRODUCTORDER]
( [ORDERID],
[COMPANYID],
[PRODUCTID],
[QUANTITY],
[PRODUCTPRICE],
[ProductSize],
[ProductColor],
[CREATEDBY],
[CREATEDAT],
[UPDATEDBY],
[UPDATEDAT]
)
VALUES
( IDENT_CURRENT('ORDER'),
1,
@PID,
@Pqty,
@PRC,
@PSIZE,
@PCOLOR,
@CUSTOMERID,
GETDATE(),
'',
''
)
END
END TRY
BEGIN CATCH
END CATCH
BEGIN TRAN
IF XACT_STATE() =0
BEGIN
COMMIT TRAN
END
ELSE
BEGIN
ROLLBACK TRAN
END
END