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

remove duplicates in an sorted array

  using System; public class HelloWorld {          public static void Main(string[] args)     {         int[] ar={2,2,3,3,4,6,6};          C...