title: Replace function requires 3 arguments
body: <p>I am trying to fetch data from SQL to excel and it is giving me the below error
  My Query in SQL Server </p>
  
  <pre><code>DECLARE @Delimiter Char(1)
  
  SET @Delimiter = CHAR(9)
  
  EXEC MSDB.dbo.sp_Send_DBMail
          @profile_name = 'K2MailSetup',        
          @Recipients='abs@test.com',        
          @Subject='Extraction Report',        
          @Body='Hi,
          Please find attached extraction report as required. ',        
          @Query='set nocount on;Select Coalesce(replace(replace(A.[type], char(10), ''), char(13), ''),'') as Type FROM [EU_OTH_REG].[dbo].[TBL_EU_OTH_TXN_REG_RSDS] A',
          @Attach_Query_Result_As_File = 1,        
          @Query_Result_Header = 1,        
          @Query_Attachment_Filename = 'Report.csv',        
          @Query_Result_Separator = @Delimiter,           
          @query_result_width =32767,
          @query_result_no_padding=1
  </code></pre>
  
  <p>========================================================================</p>
  
  <p>It is giving me below error</p>
  
  <pre><code>Msg 22050, Level 16, State 1, Line 0
  Error formatting query, probably invalid parameters
  Msg 14661, Level 16, State 1, Procedure sp_send_dbmail, Line 517
  Query execution failed: Msg 105, Level 15, State 1, Server MYKULK2DB01Q\MSSQLSTG, Line 1
  Unclosed quotation mark after the character string ') as Type
  
              FROM [EU_OTH_REG].[dbo].[TBL_EU_OTH_TXN_REG_RSDS] A
  '.
  Msg 102, Level 15, State 1, Server MYKULK2DB01Q\MSSQLSTG, Line 1
  Incorrect syntax near ') as Type
  
              FROM [EU_OTH_REG].[dbo].[TBL_EU_OTH_TXN_REG_RSDS] A
  </code></pre>
  
  <p>========================================================================</p>
  
  <p>The strange thing is that when I just run the query it provides me result but when I try to create report out of it by using the above excel steps and parameters it gives me error.</p>