Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5982087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:02:12+00:00 2026-05-22T22:02:12+00:00

i need to export 3 full sql table values in to a single excel

  • 0

i need to export 3 full sql table values in to a single excel sheet using store procedure.
i have done with single table ,

query i have used for single table :

   set @sql='bcp "select * from  Veest..ven_machinedescription_day_report " queryout   c:\Daily_Reports\data_file.csv  -c -t,  -T -S' + @@servername          
   exec master..xp_cmdshell @sql          


   --Copy dummy file to passed EXCEL file        
   set @sql= 'exec master..xp_cmdshell ''type '+@data_file+' >> "'+@file_name+'"'''        
   exec(@sql)        


  --Delete dummy file         
    set @sql= 'exec master..xp_cmdshell ''del '+@data_file+''''        
    exec(@sql) 

the above query is working fine..
for saving 3 tables values , i have done like this ,

          set @sql='bcp "select * from  Veest..ven_machinedescription_day_report " queryout   c:\Daily_Reports\data_file.csv  -c -t,  -T -S' + @@servername          
              exec master..xp_cmdshell @sql  
        set @sql1='bcp "select * from  Veest..ven_machinedescription_night_report " queryout   c:\Daily_Reports\data_file.csv  -c -t,  -T -S' + @@servername          
       exec master..xp_cmdshell @sql1  
           set @sql22='bcp "select * from  Veest..ven_machinedescription_midnight_report " queryout   c:\Daily_Reports\data_file.csv  -c -t,  -T -S' + @@servername          
      exec master..xp_cmdshell @sql2

when i saw the data_file.csv, only the last execution (@sql2) is saved..the data is not being appended.. i need output similar to the below image..

enter image description here

some times the total columns numbers will be not same in all the 3 tables..
plz help me out to solve this issue..

thanks n regards,

T.Navin

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:02:13+00:00Added an answer on May 22, 2026 at 10:02 pm

    Create a view. Then export from the view to Excel.

    CREATE VIEW vending_report
    AS
        SELECT 'A' segment, col1, col2, shift_type, col4, col5, col6
        FROM ven_machinedescription_day_report
    
        UNION ALL
    
        SELECT 'B', NULL, NULL, NULL, NULL, NULL, NULL
    
        UNION ALL
    
        SELECT 'C', col1, col2, shift_type, col4, NULL, NULL
        FROM ven_machinedescription_night_report
    
        UNION ALL
    
        SELECT 'D', NULL, NULL, NULL, NULL, NULL, NULL
    
        UNION ALL
    
        SELECT 'E', col1, col2, shift_type, col4, col5, NULL
        FROM ven_machinedescription_midnight_report
    GO
    
    SELECT col1, col2, shift_type, col4, col5, col6
    FROM vending_report
    ORDER BY segment
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can i export a data from a table to an excel sheet, using javascript?
I need to export a report to Excel file using PHP i.e. on the
i need to export my sql-server database to an excel file between day x
I need to export a oracle table to a csv/excel file format (along with
I need to export multiple data tables to Excel on the clients machine, each
I need a solution to export a dataset to an excel file without any
I have received a content export of a MOSS 2007 site which I need
I have a query filter written in human readable language. I need to parse
I need to export the data from 36 SQL tables containing 24GB of data
i need to export a pages to pdf, the pages will have grids on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.