{
I've been recently needing to generate sql scripts from large Excel spreadsheets. But once the script is finished I've had issues getting SQL Management Studio to execute as large a script in a single run. The solution? Split up the file with a little Python that takes it's arguments like this:
ipy Splitter.py LargeFile.sql 3
#import clr
#pass arguments like so:
# THISSCRIPT.PY FILE NUM_PARTS
# ipy Ringil.py LargeFile.sql 4
import sys
if(len(sys.argv) == 3):
splits = int(sys.argv[2])
f = open(sys.argv[1])
data = f.readlines()
lc = len(data)/splits
print "number of lines", len(data)
for c in range(0,splits):
outstream = open("data" + str(c + 1) + ".sql", 'w')
for line in data[:lc]:
outstream.write(line)
outstream.close()
del data[:lc]
f.close()
else:
print "Expected arguments: file and number of splits\n example: ipy Splitter.py LargeFile.sql 4"