Sybase NNTP forums - End Of Life (EOL)

The NNTP forums from Sybase - forums.sybase.com - are now closed.

All new questions should be directed to the appropriate forum at the SAP Community Network (SCN).

Individual products have links to the respective forums on SCN, or you can go to SCN and search for your product in the search box (upper right corner) to find your specific developer center.

for next statment

3 posts in General Discussion Last posting was on 2004-06-11 10:31:55.0Z
MJN Posted on 2004-06-10 15:05:07.0Z
From: "MJN" <mjn@forums.sybase.com>
Newsgroups: ianywhere.public.general
Subject: for next statment
Lines: 16
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: zaq3d73a9bc.zaq.ne.jp
X-Original-NNTP-Posting-Host: zaq3d73a9bc.zaq.ne.jp
Message-ID: <40c878a3@forums-1-dub>
Date: 10 Jun 2004 08:05:07 -0700
X-Trace: forums-1-dub 1086879907 61.115.169.188 (10 Jun 2004 08:05:07 -0700)
X-Original-Trace: 10 Jun 2004 08:05:07 -0700, zaq3d73a9bc.zaq.ne.jp
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub ianywhere.public.general:3159
Article PK: 6619

I have a table where I have added a new column and want to bulk load the
values for this column.
This column is a Long and is set for autoincrement.
So was trying to do a select and then For Next statement to update the
values for each row.
But can't get the right sql. Need the first row value to be 1001 then
increment by 1 for each row.
Can anyone give me a sample how to achieve this?
Also I have never used cursor before so if possible would like to see an
example of using a cursor and one of another method.

Thanks

ASA9.01


Nick Elson Posted on 2004-06-11 07:33:56.0Z
From: "Nick Elson" <no_spam_nicelson@sybase.com>
Newsgroups: ianywhere.public.general
References: <40c878a3@forums-1-dub>
Subject: Re: for next statment
Lines: 55
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: cpe0050bf17594c-cm014370028576.cpe.net.cable.rogers.com
X-Original-NNTP-Posting-Host: cpe0050bf17594c-cm014370028576.cpe.net.cable.rogers.com
Message-ID: <40c96064$1@forums-1-dub>
Date: 11 Jun 2004 00:33:56 -0700
X-Trace: forums-1-dub 1086939236 65.48.253.93 (11 Jun 2004 00:33:56 -0700)
X-Original-Trace: 11 Jun 2004 00:33:56 -0700, cpe0050bf17594c-cm014370028576.cpe.net.cable.rogers.com
X-Authenticated-User: techsupp
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub ianywhere.public.general:3169
Article PK: 6627

What was your ALTER TABLE statement?

If this is a true default autoincrement column, it already has
been filled in and runs from 1 to N already.

If I am correct about your starting condition, it is a simple matter
of adding 1000 to all the rows as in the example below
[of course you will only need 1 update statement]

-- drop table test; -- just in case
we need it
create table test (c1 integer, c2 integer); -- table with no
autoincrement
insert into test values (1,9,);
insert into test values (2,99,);
insert into test values (3,999,); -- just some dummy
up'ed data
insert into test values (4,9999,);
insert into test values (5,99999,);
insert into test values (6,999999,);
commit;
select * from test; -- if you
must watch
-- alter table test drop p1; -- just in case
we need it

-- *** now for the step I think you have already done ***
alter table test add p1 integer default autoincrement;
-- alter table test modify p1 integer not null; -- optional step
-- alter table test add primary key (p1); -- optional step

-- and now for the coup de grace
update test set p1=p1+1000; -- touché ?

"MJN" <mjn@forums.sybase.com> wrote in message news:40c878a3@forums-1-dub...
> I have a table where I have added a new column and want to bulk load the
> values for this column.
> This column is a Long and is set for autoincrement.
> So was trying to do a select and then For Next statement to update the
> values for each row.
> But can't get the right sql. Need the first row value to be 1001 then
> increment by 1 for each row.
> Can anyone give me a sample how to achieve this?
> Also I have never used cursor before so if possible would like to see an
> example of using a cursor and one of another method.
>
> Thanks
>
> ASA9.01
>
>


MJN Posted on 2004-06-11 10:31:55.0Z
From: "MJN" <mjn@forums.sybase.com>
Newsgroups: ianywhere.public.general
References: <40c878a3@forums-1-dub> <40c96064$1@forums-1-dub>
Subject: Re: for next statment
Lines: 68
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: flh1aad003.wky.mesh.ad.jp
X-Original-NNTP-Posting-Host: flh1aad003.wky.mesh.ad.jp
Message-ID: <40c98a1b$1@forums-1-dub>
Date: 11 Jun 2004 03:31:55 -0700
X-Trace: forums-1-dub 1086949915 218.227.163.211 (11 Jun 2004 03:31:55 -0700)
X-Original-Trace: 11 Jun 2004 03:31:55 -0700, flh1aad003.wky.mesh.ad.jp
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub ianywhere.public.general:3170
Article PK: 6630

Yeap my mistake was doing things thru central not in ISQL.
It is becoming a bad habit.
Thanks

"Nick Elson" <no_spam_nicelson@sybase.com> wrote in message
news:40c96064$1@forums-1-dub...
> What was your ALTER TABLE statement?
>
> If this is a true default autoincrement column, it already has
> been filled in and runs from 1 to N already.
>
> If I am correct about your starting condition, it is a simple matter
> of adding 1000 to all the rows as in the example below
> [of course you will only need 1 update statement]
>
> -- drop table test; -- just in
case
> we need it
> create table test (c1 integer, c2 integer); -- table with no
> autoincrement
> insert into test values (1,9,);
> insert into test values (2,99,);
> insert into test values (3,999,); -- just some
dummy
> up'ed data
> insert into test values (4,9999,);
> insert into test values (5,99999,);
> insert into test values (6,999999,);
> commit;
> select * from test; -- if you
> must watch
> -- alter table test drop p1; -- just in case
> we need it
>
> -- *** now for the step I think you have already done ***
> alter table test add p1 integer default autoincrement;
> -- alter table test modify p1 integer not null; -- optional
step
> -- alter table test add primary key (p1); -- optional
step
>
> -- and now for the coup de grace
> update test set p1=p1+1000; -- touch・瘢雹?
>
>
>
> "MJN" <mjn@forums.sybase.com> wrote in message
news:40c878a3@forums-1-dub...
> > I have a table where I have added a new column and want to bulk load the
> > values for this column.
> > This column is a Long and is set for autoincrement.
> > So was trying to do a select and then For Next statement to update the
> > values for each row.
> > But can't get the right sql. Need the first row value to be 1001 then
> > increment by 1 for each row.
> > Can anyone give me a sample how to achieve this?
> > Also I have never used cursor before so if possible would like to see an
> > example of using a cursor and one of another method.
> >
> > Thanks
> >
> > ASA9.01
> >
> >
>
>