ISQL help in DOS

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
agrawal.meet
Posts: 15
Joined: 14 Jun 2010 06:50

ISQL help in DOS

#1 Post by agrawal.meet » 16 Jul 2010 07:58

Hi All,

I am trying to execute a query using ISQL. Query is written in different file. Below is the command I used:

Code: Select all

isql -U <user> -P <pwd> -S <server> -D <database> -i d:\apps\cat\sql\cit_feed_getCOB.sql -o d:\apps\cat\dat\cit_date.dat


Output in cit_date.dat is:

Code: Select all

          
 --------
 20100715

(1 row affected)


But I only want isql to print data not other things. Output should be like:

Code: Select all

20100715


Can you please tell me how can I achieve this? Again...I am not doing bcp on the table..just selecting one column.

Thanks is advance,
Meet

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: ISQL help in DOS

#2 Post by aGerman » 16 Jul 2010 08:10

I never used it, but have a look to the msdn:
http://msdn.microsoft.com/en-us/library/Aa214012

What about -h-1 ?

Regards
aGerman

agrawal.meet
Posts: 15
Joined: 14 Jun 2010 06:50

Re: ISQL help in DOS

#3 Post by agrawal.meet » 16 Jul 2010 08:14

Thanks for response. But -h-1 is not working :(

agrawal.meet
Posts: 15
Joined: 14 Jun 2010 06:50

Re: ISQL help in DOS

#4 Post by agrawal.meet » 16 Jul 2010 08:19

I was able to remove "1 rows effected". Can we modify the file and pick up only data into variable. I know it will always be at line 3 :)

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: ISQL help in DOS

#5 Post by aGerman » 16 Jul 2010 08:30

If that means the data is in the last row of the file:

Code: Select all

for /f "usebackq delims=" %%a in ("d:\apps\cat\dat\cit_date.dat") do set "yourVar=%%a"
echo %yourVar%


Regards
aGerman

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

Re: ISQL help in DOS

#6 Post by avery_larry » 16 Jul 2010 12:26

Perhaps slightly more efficient than aGerman:

If you're CERTAIN that it's on line 3, then:

Code: Select all

for /f "skip=2 usebackq delims=" %%a in ("d:\apps\cat\dat\cit_date.dat") do set "yourVar=%%a"&goto continue
:continue
echo yourvar=%yourvar%


The "&goto continue" part is only needed if the 3rd line is NOT the last line.

Basically, the skip=2 part will skip the first 2 lines, and the "&goto continue" will skip all the lines after the 3rd.

ghostmachine4
Posts: 319
Joined: 12 May 2006 01:13

Re: ISQL help in DOS

#7 Post by ghostmachine4 » 16 Jul 2010 19:22

agrawal.meet wrote:[/code]
But I only want isql to print data not other things. Output should be like:

Code: Select all

20100715



download sed for windows, then do this

Code: Select all

c:\>  sed "/-/d;/row affected/d" d:\apps\cat\dat\cit_date.dat


use a for loop to capture the output if you want

agrawal.meet
Posts: 15
Joined: 14 Jun 2010 06:50

Re: ISQL help in DOS

#8 Post by agrawal.meet » 19 Jul 2010 00:38

Thanks everyone for their timely reply. I am going ahead with aGerman's suggestion as my output to the file is being appended. So, not sure anymore if it will be at line 3.

Thanks again.

Thanks,
Meet

Post Reply