Insert bulk values in DB table using isql

Hello,

Objective is to insert bulk values in DB table using isql.

Following code tried:

isql -SServer_name -Ddb_name -Uuser_name -Ppassword < file.txt
cat file.txt
for i in `cat data_value_file.txt`
do
insert into tempdb..temp_table11 values ('$i')
go
done
cat data_value_file.txt
A60B12816
C61D16666
E63F44627
G66H74669
I75J80839

Error recieved:

 
Msg 156, Level 15, State 2:
Server 'SERVER_NAME', Line 1:
Incorrect syntax near the keyword 'for'.

Please help to insert bulk data where I only have to pass valued in a flat file.

Thank you,
Manish

why don't use bcp ? Do you have specific requirements?

bcp utility is not available in the system, so trying find out some workaround.

Thank you.

Ok, please show us the sample from your input file.

From the error message, I think you are mixing db and shell commands.
Everything after the heredoc, must be a valid db command.

In this case, you first need to start loop then connect the db.

something like,

for i in `cat data_value_file.txt`
do
 isql. .....
 inset...
 go
 exit
done

Some suggestions :

  1. use while loop to read the file
while read i
do

done < data_value_file.txt
  1. Now you have to connect and disconnect the db multiple times. which is inefficient Hence its better to create the insert statements externally (via script) and then push that file into db at one shot. (I guess isql -i <input_file> )