I want to call a sql file in my shell script. see the below code:-
if [[ "${MODE}"="FULL" ]]
then
(
isql -U${S_USER} -S${S_SERV} -w100 -b -h0 <<ENDSQL | sed -e "s/Password://"
${S_PWD}
set nocount on
go
use ${S_DB}
go
// need to call a file name XYZ.sql
go
ENDSQL
)
if the mode =full, then connect via using isql (command) with given paramters as (server_user, server_id, password).
xyz.sql file contains like 20sql commands in it. i am not sure how will i call that file in here. {i want to call the file because i am using that same file in different calls also, thats why not pasting sql commands here}
ending ENDSQL MUST be in the beginning of the line.
I understood, you wish to take queries from an input file instead writing.
that's why I suggested -i option.
from the sybase man page ( I assume you using sybase databse ?)
-i inputfile
specifies the name of the operating system file to use for input to isql. The file must contain command terminators (�go� is the default).
*
Specifying the parameter as follows is equivalent to < inputfile:
-i inputfile
*
If you use -i and do not specify your password on the command line, isql prompts you for it.
*
If you use < inputfile and do not specify your password on the command line, you must specify your password as the first line of the input file.
No, I was talking about the ending label. ( the second one)
isql -U${S_USER} -S${S_SERV} -w100 -b -h0 <<ENDSQL | sed -e "s/Password://"
${S_PWD}
set nocount on
go
use ${S_DB}
go
// need to call a file name XYZ.sql
go
ENDSQL ## this MUST be in the beginning of the line. no space or tabs before it
EDIT: Label name doesn't matters. It can be anything. SQL, sql,hi or even your name
yippe. (thanks a ton) . i figured out hw to call a file finally. bt hw do i interpret this data in the fields required by me is the next step. o..
select account_no into tempdb..sun from ABC
go
i am selecting account_no into tempdb creating sun table and copying data from ABC. (this is working fine, i mean i am able to create the table).
and the isql command i am running the one which u told me:-
Retrieve_Date()
{
if [[ "${MODE}" = "FULL" ]]
then
(
isql -U${S_USER} -S${S_SERV} -D${S_DB} -P${S_PWD} -b -h0 -i${MYDIR}/abc.sql << FINSQL
go
FINSQL
) > XYZ.txt
fi
I wanted to know how can i get the result of the sql query performed in abc.sql into a variable in my shell script. so that i can use those records. i am checking the database and i am seeing a temp. table being created but unable to get those records in my script. any ideas??
hey, thanks a ton again.
actually i am pulling some data from abc.sql into temp.db. i am storing this in a table called XYZ in tempdb.
and i am using bcp tool so that i can get that data into my file.
i m using the below code :-
Retrieve_Date()
{
if [[ "${MODE}" = "FULL" ]]
then
(
isql -U${S_USER} -S${S_SERV} -D${S_DB} -P${S_PWD} -b -h0 -i${MYDIR}/abc.sql << FINSQL
go
FINSQL
) > sun.txt
fi
(
bcp tempdb..ASH in ${MYDIR}/takeit.txt -c -t"|" -U${S_USER} -S${S_SERV} -P${S_PWD} << FINBCP
FINBCP
) > ART.txt
I want the data fetched from abc.sql (queries) to be stored in takeit.txt (i actually want it in the file takeit.txt)
so that i can take ftp file and forward it some place else.
i think u wud have got bored of me thanking again and again.
btw all this exercise of me learning gone to waste. those idiots want something else nw... GRRRR
bt i m thankful to them in a hideous way becuase i learnt a lot
i will tried out the bcp command its not working currently. it gives the below error any clues??
Starting copy...
The BCP hostfile '/home/cadessad/bin/takeit.txt' contains only 0 rows. It was impossible to read the requested number of rows.
bcp copy in failed
grrrrr me noob.
i was using out earlier when i used the command first time. bt then a friend said no it has to be in..
i will change it right now.. and check
---------- Post updated at 09:33 AM ---------- Previous update was at 09:28 AM ----------
see the below output of bcp.. it works ... yeeyeyeyeyeyeyeyyeyee :rolleyes::rolleyes::rolleyes::rolleyes::rolleyes::p:p:p:p