create update combined sql server procedure

CREATE PROCEDURE [dbo].[sp_CreateUpdateCompany]
(
    -- Add the parameters for the stored procedure here
 	@CompanyId	    uniqueidentifier = '00000000-0000-0000-0000-000000000000',
	@CompanyName	    nvarchar(250),
	@UserID		    nvarchar(128),
	@OrganizationId	    int = 0,
	@outPutId	    int Output
)
AS

BEGIN

       IF(@CompanyId <> '00000000-0000-0000-0000-000000000000')
	     BEGIN

			UPDATE [dbo].[Company]
			   SET 
				   [CompanyName] = @CompanyName
				  ,[ModifiedBy] =  @UserID
				  ,[ModifiedOn] =  GETDATE()
				  ,[OrganizationId] = @OrganizationId
			 WHERE [CompanyId] = @CompanyId

				SET @outPutId =  1

		 END
		 ELSE 
		   BEGIN
				INSERT INTO [dbo].[Company]
					   (   
				            [CompanyName]
					   ,[CreatedBy]
					   ,[CreatedOn]
					   ,[ModifiedBy]
					   ,[ModifiedOn]
					   ,[OrganizationId]
					   )
				 VALUES
					   (
				            @CompanyName
					   ,@UserID
					   ,GETDATE()
					   ,@UserID
					   ,GETDATE()
					   ,@OrganizationId
					   )

					SET @outPutId =  1
		   END
END

Post a Comment

0 Comments