dickiebird
Programmer
Hi Guys
This is Sybase really, but the same principle applies( I think ) across all DBs.
In a shellscript on a Unix server, I want to loop through an entire table and format the output ( if there was no need to format I'd just select * from tablename and output it to a file.)
Here's what I've tried - all I get is the last row of the table.
OUTFILE=/tempts/test2
isql -Usa -Psa > $OUTFILE <<END
use sdb
go
declare @printline1 varchar(55)
declare @agent varchar(10)
declare @short_na varchar(30)
/*Dummy to set @@rowcount > 0 ?? */
select min(agent_code) from agent
/* loop round all AGENTS */
while (@@rowcount != 0 )
begin
select @agent=ltrim(rtrim(substring(agent_code, 2, 9))),
@short_na=short_na
from agent
while (@@rowcount != 0 )
begin
select @printline1 = @agent + '|' + @short_na
print @printline1
end
end
go
END
This is a cut-down version - there's many more variables and inserted text - removed for clarity.
Anyone got any thoughts, please Dickie Bird
db@dickiebird.freeserve.co.uk
This is Sybase really, but the same principle applies( I think ) across all DBs.
In a shellscript on a Unix server, I want to loop through an entire table and format the output ( if there was no need to format I'd just select * from tablename and output it to a file.)
Here's what I've tried - all I get is the last row of the table.
OUTFILE=/tempts/test2
isql -Usa -Psa > $OUTFILE <<END
use sdb
go
declare @printline1 varchar(55)
declare @agent varchar(10)
declare @short_na varchar(30)
/*Dummy to set @@rowcount > 0 ?? */
select min(agent_code) from agent
/* loop round all AGENTS */
while (@@rowcount != 0 )
begin
select @agent=ltrim(rtrim(substring(agent_code, 2, 9))),
@short_na=short_na
from agent
while (@@rowcount != 0 )
begin
select @printline1 = @agent + '|' + @short_na
print @printline1
end
end
go
END
This is a cut-down version - there's many more variables and inserted text - removed for clarity.
Anyone got any thoughts, please Dickie Bird
db@dickiebird.freeserve.co.uk