Thursday, January 14, 2010

Custom Error in Sql Server 2008

declare @un tinyint
declare @UserName Varchar(200) = 'abc'
declare @RoleID int = 3
select @un = COUNT(*) from LoginDetails where UserName = @UserName and RoleID = @RoleID
if @un > 0
begin
declare @ErrorMessage1 nvarchar(max), @ErrSeverity1 int
set @ErrorMessage1 = 'UserName Already Exists. Try different User Name'
set @ErrSeverity1 = 16
RAISERROR(@ErrorMessage1, @ErrSeverity1, 1)
end

No comments:

Post a Comment