title: How to modify python script to append data on file using sql server 2019?
body: <p>I need to append data to excel file already exist from table students on SQL Server .</p>
  <p>Excel file already Created on <code>D:\ExportExcel\dbo.students.xlsx</code> with student IDs 1 and 2.</p>
  <p>Table Insert Commands:</p>
  <pre><code>INSERT [dbo].[students] ([StudentId], [Name]) VALUES (3, N'Sayed')
  INSERT [dbo].[students] ([StudentId], [Name]) VALUES (4, N'Michel')
  </code></pre>
  <p>Python script used</p>
  <pre class="lang-sql prettyprint-override"><code>DECLARE @PythonScript NVARCHAR(MAX) = N''
    declare @SQL NVARCHAR(MAX) = N'select studentid,Name from dbo.students;'
    declare @ExportPath varchar(max)='D:\ExportExcel\'
    declare @TableName varchar(max)='dbo.students'
    declare @FullFilePath varchar(max) = concat(@ExportPath,@TableName+'.xlsx')
  
     
  SET @PythonScript = N'
  FullFilePath = ExcelFilePath+TableName+&quot;.xlsx&quot;
  InputDataSet.to_excel(FullFilePath,sheet_name=TableName.split(&quot;.&quot;)[-1],index=False)'
     
  EXEC   sp_execute_external_script
        @language = N'Python'
       ,@script = @PythonScript
       ,@input_data_1 = @SQL
       ,@params = N'@ExcelFilePath NVARCHAR(MAX), @TableName NVARCHAR(200)'
       ,@ExcelFilePath = @ExportPath -- file path where Excel files are placed
       ,@TableName = @TableName
  
  </code></pre>
  <p>When use Python script explain  it will not append data to Excel file from table students. Meaning it will not add student IDs 3 and 4 .</p>
  <p>So How to append data from table students to excel file using Python script?</p>
  <p>Expected result to file after append</p>
  <p><a href="https://i.stack.imgur.com/xbkVV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xbkVV.png" alt="after append data to same path" /></a></p>