Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

output from a variable table

Status
Not open for further replies.

grinder182533

Programmer
Oct 11, 2006
2
GB
I have a table defined as follows :

F1 key 3 chars
F2 numb 1 number
F3 text 10 chars

So I could have data as follows :
AAA1aaaaaaaaa1
BBB1bbbbbbbbb1
BBB2bbbbbbbbb2
CCC1ccccccccc1
DDD1ddddddddd1
DDD2ddddddddd2
DDD3ddddddddd3

I need to write a SyBase script to output as follows :-
AAA
1
aaaaaaaaa1
{page throw}
BBB
1
bbbbbbbbb1
2
bbbbbbbbb2
{page throw}
CCC
1
ccccccccc1
{page throw}
DDD
1
ddddddddd1
2
ddddddddd2
3
ddddddddd3
{page throw}
{end of file}

I have only done simple selects up till now.

Any help greatly appreciated
Many thanks
 
You will need to use a stored procedure that posts into a temporary table (#table) then do a select on that.

eg)

CREATE STORED PROCEDURE sp1
AS
BEGIN
CREATE TABLE #temp (f1 VARCHAR(10))

<create a cursor over your table>

<if f1 has changed then insert into temp page break (if not first) and then f1>
<if f1 hasn't changed then insert f2 then f3>

<loop though records to end>
<insert another page break and eof>

last statement in sp should be "select f1 from #temp"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top