1.

Solve : execute a query on sybase Database and store back the result in a variable?

Answer»

Apologies If this question is not meant for this forum.
But since I am using a batch file, I thought someone might have used this before.

A small part of my batch file includes EXECUTING a query on sybase database. I want to store back the result in a variable or atleast check whether the result was SUCCESSFUL and based on this execute another set of lines.

For this I am using "isql" utility.

Here is the syntax for the same.

isql -S %server% -D %database% -U %user% -P %pwd% -i test.sql

Is there a way to store back the result in batch files.Batch code is text based. You can iterate line by line the results of a command:

Code: [Select]for /f "tokens=* delims=" %%v in ('isql -S %server% -D %database% -U %user% -P %pwd% -i test.sql') do (
.
. Your commands go here %%v contains a single line of output from the isql command
.
)

There are many variations on the for command. Depending on what you doing, some keywords can be very helpful, some not so much.

Good luck. Works LIKE a charm.

Many thanks Sidewinder. Appreciate it!!!using your code which works perfect:
for /f "tokens=* delims=" %%v in ('isql -S %server% -D %database% -U %user% -P %pwd% -i test.sql') do (
echo %%v
)

Basically the output I get is full of spaces and tabs and this is an issue with the Database output.

prioran GSD

agerma GSD

savlahi DEV

rotheam DEV
I want to REMOVE the tabs and spaces in between and set the first variable to the second. If this is confusing Apologies for my bad english.
let me give you an example.

set prioran=GSD and so on.

I know this needs a for loop and FINDSTR. Could anyone help?



Discussion

No Comment Found