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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using Isql for SQL SERVER to get the table rows counts in UNIX shell script to
# 1  
Old 03-18-2017
RedHat 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.

Code:
isql -v DSN USERNAME PASSWD


here is what i am looking for:

Code:
VARIABLE_NAME=`ISQL DSN USERNAME PWD SELECT COUNT(1) FROM $SRC_TABLE `


Last edited by Don Cragun; 03-18-2017 at 01:09 AM.. Reason: Add CODE and ICODE tags again.
# 2  
Old 03-18-2017
isql does't affect the database !

Isql commands affect the running of isql itself and do not affect the database or data in any way.


Examples
Code:
$ isql WebDB MyID MyPWD -w -b < My.sql

Connects to the WebDB as user MyID with password MyPWD, then
execute the commands in the My.sql file and returns the results
wrapped in HTML table. Each line in My.sql must contain exactly
1 SQL command, except for the last line, which must be
blank (unless the -n option is specified).

-n Use the new line processing. (multiple lines of SQL, terminated with command GO).

Last edited by vbe; 03-18-2017 at 07:39 AM.. Reason: missing code tag
# 3  
Old 03-18-2017
Also, try the command "set nocount on" to suppress the feedback message from the query... (the pesky line that says something like "<N> rows affected" that shows up after each SQL statement)

Code:
$
$  cat -n fetch_count_1.sql
     1	use pubs2
     2	go
     3	select count(*) from sales
     4	go
$
$  VAR1=`isql dsn user password -w -b < fetch_count_1.sql`
$  echo $VAR1
30 (1 row affected)
$
$
$  cat -n fetch_count_2.sql
     1	use pubs2
     2	go
     3	set nocount on
     4	select count(*) from sales
     5	go
$
$  VAR2=`isql dsn user password -w -b < fetch_count_2.sql`
$  echo $VAR2
30
$
$

# 4  
Old 03-18-2017
getting error message could not SQLexecute

getting error message could not SQLexecute.
# 5  
Old 03-18-2017
Quote:
Originally Posted by pimmit22043
getting error message could not SQLexecute.
That doesn't tell me anything.
# 6  
Old 03-18-2017
Thank you so much Tyler,

when i run the following command with out -w, it displaying the count with long warning message saying that
ODBC Data direct for SQL SERVER is exclusive to ETL tool. when i try to use it shell script it warning!

Code:
VAR2=`isql dsn user password -b < fetch_count_2.sql`

# 7  
Old 03-18-2017
Quote:
Originally Posted by pimmit22043
... when i run the following command with out -w....
Why do you omit the "-w" switch?
What do you see if you do use the "-w" switch?

Quote:
Originally Posted by pimmit22043
...
...
it displaying the count with long warning message saying that
ODBC Data direct for SQL SERVER is exclusive to ETL tool.
...
I don't see it in your post.

Quote:
Originally Posted by pimmit22043
...
...when i try to use it shell script it warning!
...
I don't see this in your post either.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Write a shell script for SQL loader to load data into a staging table

Hi, I'm new to Linux. I'm working on a database, and need to load data in a database table (which I already created) using shell script. The table has two columns - Acct_number (not nullable) and date (timestamp). I'm not able to write a shell script for that. Can any one help me? ... (3 Replies)
Discussion started by: saisudeep
3 Replies

2. Shell Programming and Scripting

connecting to table to extract multiple rows into file from unix script

I need to extract the data from oracle table and written the below code. But it is not working.There is some problem with the query and output is shown is No rows selected" . If I run the same query from sql developer there is my required output. And if I run the shell script with simple sql... (7 Replies)
Discussion started by: giridhar276
7 Replies

3. Shell Programming and Scripting

How to get full sql table data using shell script

i have a Oracle table like col1 col2 ---- ----- a 1 b 2 c 3 when i write a script for it , it gives me all the data in one column. Please give me the solution which gives the exact result like we see in sql editors. for a in `echo " set feedback off; set pagesize 40;... (1 Reply)
Discussion started by: ss135r
1 Replies

4. Shell Programming and Scripting

Script to compare table counts...

Hello all, I am very new to unix. I am working on a DB upgrade. The requirement is to get count of all the tables in the database before and after upgrade and compare them. I found the below query to find the counts of all the tables: nawk -v v="'" '{ print("select " v ":" $1":" v... (2 Replies)
Discussion started by: vkrisaak
2 Replies

5. Shell Programming and Scripting

connect to SQL server from shell script

Hi all, I need to connect to SQL server from shell script. Then need to execute queries from shell script. Kindly let me know on how to do this Thanks, Ananthi.U (1 Reply)
Discussion started by: ananthi_ku
1 Replies

6. Shell Programming and Scripting

Shell script to extract rows from table

I have an Employee with EID, ENAME and ESTATUS as columns in SQL. I want to extract the status of an employee and update the details if the status is 'A'. Can anyone help in writing the shell script. (1 Reply)
Discussion started by: vkca
1 Replies

7. Shell Programming and Scripting

how to execute shell script in another server that contain sql.

hi all, how to execute shell script in another server that contain sql script. i tried using "ssh -l" option.. but i am unable to load the environment variable of the remote host. please suggest how execute the shell script contain sql part inside it. (2 Replies)
Discussion started by: sandeep909
2 Replies

8. Solaris

bcp and isql for MS SQL Server on Solaris?

After dumping data from an Oracle database running on Solaris into a flat file, we need to run bcp and isql for MS SQL Server on the same Solaris box. Does Microsoft provide some tools that run on Unix? Thanks for your assistance. (2 Replies)
Discussion started by: tomstone_98
2 Replies

9. Shell Programming and Scripting

How to pass pl/sql table values to shell script

Hello, i am using '#!/bin/bash', i want to make a loop in pl/sql, this loop takes values from a table according to some conditions, each time the loop choose 3 different variables. What i am not able to do is that during the loop i want my shell script to read this 3 variables and run a shell... (1 Reply)
Discussion started by: rosalinda
1 Replies

10. Shell Programming and Scripting

isql query in unix shell script

Dear all I want to execute some isql command from unix shell script. Kindly suggest me. isql command mention below. isql -U -P use gdb_1 go select count (*) from table_x go (3 Replies)
Discussion started by: jaydeep_sadaria
3 Replies
Login or Register to Ask a Question