Wednesday 20 June 2012

To read sql error log through T-SQL command


system extended stored procedure xp_readerrrorlog use to read errorlog
  • Parameter 1 Type :- INT
    Name :- Error Log File
    Default Value  :- 0
    Description  :- 0 for current, 1 for Archive #1, 2 for Archive #2, and so on
  • Parameter 2 Type :- INT
    Name :- Log File Type
    Default Value :- 1
    Description :- 1 for error log and 2 for SQL Server Agent log
  • Parameter 3 Type :- Varchar (255)
    Name :- Search String 1
    Description :- String one wants to search in error log
  • Parameter 2 Type :- varchar (255)
    Name :- Search String 2
    Description :- Its second string which can be searched to refine the search result 
Following example show whole error log of sql server
exec xp_readerrorlog 0,1,null,null

Monday 18 June 2012

Function to replace all special characters

CREATE FUNCTION dbo.RemoveSpecialCharacter(@Str NVARCHAR(MAX)) RETURNS NVARCHAR(MAX)
AS
BEGIN
    SET @Str = Replace(@str, Char(13), ' ') --replace all enters with space
    SET @Str = Replace(@str, Char(9), ' ')--replace all tabs with space
    SET @Str = Replace(@str, Char(10), ' ')--replace all line feeds with space
    RETURN @Str
END