Friday, 17 May 2024

Add and Update bulk records to table in sql using UDDT(userdefined datatables)


                GLCode,

                CreatedBy,

                ModifiedBy,

                CreatedOn,

                ModifiedOn

            )

            VALUES (

                Source.PurchaseOrderId,

                Source.Quantity,

                Source.UnitPrice,

                Source.Description,

                Source.GLDescriptionId,

                Source.GLCode,

                Source.CreatedBy,

                Source.ModifiedBy,

                ISNULL(Source.CreatedOn, GETDATE()),

                ISNULL(Source.ModifiedOn, GETDATE())

            );


        -- Handle deletions if necessary (optional)

        -- WHEN NOT MATCHED BY SOURCE THEN

        --    DELETE;


        -- Return a success message

        SELECT 1 AS [Status], 'Items have been added/updated successfully.' AS [Message];

    

    END TRY

    BEGIN CATCH

        -- Handle any errors

        SELECT 

            ERROR_NUMBER() AS ErrorNumber,

            ERROR_SEVERITY() AS ErrorSeverity,

            ERROR_STATE() AS ErrorState,

            ERROR_PROCEDURE() AS ErrorProcedure,

            ERROR_LINE() AS ErrorLine,

            ERROR_MESSAGE() AS ErrorMessage;


        -- You might want to re-throw the error

        -- THROW;

    END CATCH

END;

No comments:

Post a Comment

7 Common mistakes in Dot Net — You can avoid

  There are many common mistakes made during .NET (ASP.NET, .NET Core) development, which affect performance, security, and code… Code Crack...