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

  • SEARCH
  • Home
  • 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 8764761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:06:53+00:00 2026-06-13T16:06:53+00:00

All, I have developed an export mechanism to allow the selected tables from a

  • 0

All, I have developed an export mechanism to allow the selected tables from a givem database to be exported to .csv files; I can do this using bcp or sqlcmd. For large tables (> 1-2GB), I want to split the tables into several .csv files of a predetermined, user specified size (say 200MB).

How can I determine the number of rows that make up the users specified size? This is so I can use a sqlcmd command like the following

DECLARE @sql VARCHAR(8000);
SELECT @sql = 'sqlcmd -S' + @@SERVERNAME + ' -E -Q ' + 
              '"SELECT * FROM Ia.dbo.[Episode];" -o "F:\aaData\Test2.csv" -s"," -W';
EXEC master..xp_cmdshell @sql;

with a TOP N clause to get the correct split .csv size. I may have to count the rows using a batch read, or is there a better way to do this?

  • 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-06-13T16:06:54+00:00Added an answer on June 13, 2026 at 4:06 pm

    If you want your exported files to be as close to the user’s specified size as possible, you’re going to need to resort to a more programmatic approach. Consider:

    public void Export( int fileSize )
    {
        SqlDataReader reader = // command to return the recordset to export...
    
        int bytesLeft = fileSize;
    
        // open first output file
        while ( reader.Read() )
        {
            // write the row
            bytesLeft -= // length of the row you just wrote
    
            if ( bytesLeft <= 0 )
            {
                // close this file
                // open the next file
                bytesLeft = fileSize;
            }
        }
    
        // close the last file.
    }
    

    This answer is intended to emphasize the mechanics of splitting a file that you’re exporting. The details of reading data and writing a text file I’ve left out, but you can get more information on those by reading about SqlDataReader and writing text files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed a custom c# cmdlet. It has three parameters (all of them
I have developed a html css code. It works perfect on all browsers but
We have three developers and one tester all working against the same database. We
I have users table. There are three other tables: developers, managers, testers. All of
I have a shed load of 'aps_developer_identity.cer' certificates exported from iPhone Developer portal. They
I have developed a program which uses SQLite 3.7 ... database, in it there
I have already developed a fully-functioning website, and our team is looking to export
I have developed a web application driven by a mysql database that stores information
On large-scale Java/.Net Enterprise projects, does every developer need to have all the components/libraries/dependencies
I have heard that GTK covers all controls so that developers do not care

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.