Wednesday 17 September 2014

Stored Procedure to Validate duplicate entry for same user at the time of insert and update


/****** Object:  StoredProcedure [dbo].[proc_IsExistUser]    Script Date: 09/18/2014 08:23:03 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

--exec [proc_IsExistCategory] 'aa'   
CREATE Procedure [dbo].[proc_IsExistUser]          
 (     
  @UserId bigint, 
  @UserName varchar(50)     
 )     
AS       
           
BEGIN      
       
 Begin Try   
 if (@UserId = 0)     
   select * from View_Users where UserName =@UserName      
 else 
   select * from View_Users where UserName =@UserName and UserId <> @UserId     
  
           
 End Try       
       
 BEGIN CATCH       
       
     return  '0';       
       
 END CATCH       
       
END
GO

No comments:

Post a Comment