Insert bulk values in DB table using isql


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Insert bulk values in DB table using isql
# 1  
Old 01-22-2014
Insert bulk values in DB table using isql

Hello,

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

Following code tried:
Code:
isql -SServer_name -Ddb_name -Uuser_name -Ppassword < file.txt

Code:
cat file.txt
for i in `cat data_value_file.txt`
do
insert into tempdb..temp_table11 values ('$i')
go
done

Code:
cat data_value_file.txt
A60B12816
C61D16666
E63F44627
G66H74669
I75J80839

Error recieved:
Code:
 
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
# 2  
Old 01-22-2014
why don't use bcp ? Do you have specific requirements?
# 3  
Old 01-22-2014
bcp utility is not available in the system, so trying find out some workaround.

Thank you.
# 4  
Old 01-22-2014
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,

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



Some suggestions :
1. use while loop to read the file

Code:
while read i
do

done < data_value_file.txt


2. 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>)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using Isql for SQL SERVER to get the table rows counts in UNIX shell script to

need to create shell script to read the table's name from file and connect SQL SERVER using isql (odbcunix) i 'm able connect to database with below command line syntex but i could not get working in shell script with SQL and storing the row count in variable. isql -v DSN USERNAME PASSWD ... (6 Replies)
Discussion started by: pimmit22043
6 Replies

2. Shell Programming and Scripting

Insert one table and update another with shellscript

I have a problem with my shell script. I want to insert data from file to table1(empty) and then, compare table1 with table2 and update some fields. The first part is correct, but the second part does not work. The only way it works is if after the first part I truncate table1 and run the script... (1 Reply)
Discussion started by: nika_mill
1 Replies

3. Shell Programming and Scripting

awk file to read values from Db2 table replacing hard coded values

Hi, I want to replace a chain of if-else statement in an old AWK file with values from Db2 table or CSV file. The part of code is below... if (start_new_rec=="true"){ exclude_user="false"; user=toupper($6); match(user, "XXXXX."); if (RSTART ==2 ) { ... (9 Replies)
Discussion started by: asandy1234
9 Replies

4. Shell Programming and Scripting

Values passing out of isql session

hi .. i have a isql session which inside which i have two variables defined.. i wanna calculate % based on those variables. i knw i can easily do % calculation in csh if i could get the value of these variables passed outside the isql session . is tat possible ?? pls advice somthin like below... (1 Reply)
Discussion started by: Rahul619
1 Replies

5. Programming

Table Locking in Insert Command.

Hi, i have a java based tool which does insert operation in a TABLE, and in parallel the same table is used by my C++ code which does select Query. the Table will be always busy, but sometimes the table is getting locked when i try to make an insert, am bit confused whether the lock is... (0 Replies)
Discussion started by: senkerth
0 Replies

6. Shell Programming and Scripting

Query the table and return values to shell script and search result values from another files.

Hi, I need a shell script, which would search the result values from another files. 1)execute " select column1 from table_name" query on the table. 2)Based on the result, need to be grep from .wft files. could please explain about this.Below is the way i am using. #!/bin/sh... (4 Replies)
Discussion started by: Rami Reddy
4 Replies

7. Shell Programming and Scripting

Insert into Oracle table thru UNIX - linux 2.6.9-89

Hi, I am trying to insert a record into a table (say dips_tbl) which resides in Oracle DB through a ksh script. I want to insert records into few of the table columns-not all. I'll give an e.g. for the date column "CREATE_DATE". For that I first execute SQL1="SELECT SYSDATE FROM DUAL" ... (1 Reply)
Discussion started by: dips_ag
1 Replies

8. Shell Programming and Scripting

select values from db1 table and insert into table of DB2

Hi I am having three oracle databases running in three different machine. their ip address is different. from one of the DB am able to access both the databases.(means am able to select values and insert values in to tables individually.) I need to fetch some data from DB1 table(say DB1 ip is... (2 Replies)
Discussion started by: aemunathan
2 Replies

9. Ubuntu

Ubuntu Bulk Insert to Windows SQLServer

Hi, Anyone can help me, I can connect from ubuntu "freetds driver" to Windows sqlserver Database and doing select, insert, update, etc. But when I try to use the Bulk Insert with these command; 1> BULK INSERT test FROM '/home/test/test.txt' WITH (FIRSTROW = 2, CODEPAGE = 'ACP',... (2 Replies)
Discussion started by: dba_macau
2 Replies

10. Shell Programming and Scripting

get values from isql query

hi all i have an isql sentence in a ksh script, what get some values from my database (Sybase IQ 12.5 - solaris 5.7) how can i read this sql results??? do i have to do a while?? a for??? where do i put the values?? my idea is put them in an array, is that possible? please, help me... (3 Replies)
Discussion started by: DebianJ
3 Replies
Login or Register to Ask a Question