Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Virtual autoincrement column

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-05-06 : 14:53:29
Robert writes "I will confess I haven't read the entire SQL Books online. However, I have spent significant time consulting SQL Books online in an attempt to achieve the desired result. I am now consulting the web in hopes of guidance and discovered this page.

I read with great interest the following code which was posted:

declare @intCounter int
set @intCounter = 0
update _deltime
SET @intCounter = empl_uno = @intCounter + 1

Select * from _deltime

It is very close to what I would like to achieve but not quite.

I would like to return 8 columns resulting in nth [assume 56] rows of data. I want to place in the view a virtual autoincrementing number assignment to each row. For Example;

1 + 8 cols of data
2 + 8 cols of data
3 + 8 cols of data
4 etc

The numbering doesn't exist in the table nor do I want to alter the table or column.

We run SQL 7.0 NT ver 4.0 SP6a

Is a Virtual autoincrement column possible?

My current code which of course doesn't include this elusive autoincrementer:

set Nocount on
declare @emp as int
declare @msg char(150), @init char(4), @eName char (40), @log char(20)

/*create 1st cursor*/
declare rsf1 cursor for
select empl_uno from _deltime

Open rsf1

fetch next from rsf1 into @emp

while @@fetch_status=0
Begin
Select @msg = "Employee: "

Print @msg

declare rsf2 cursor for
select pl.employee_name, pl.initials, pl.login
from hbm_persnl pl
where pl.empl_uno=@emp

open rsf2
fetch next from rsf2 into @eName, @init, @log

if @@fetch_status <> 0
print " <> "

while @@fetch_status=0
Begin

select @msg = @eName + " Login: " + @log + " Initials: " + @init
print @msg
fetch next from rsf2 into @init, @eName, @log

end

close rsf2
deallocate rsf2

fetch next from rsf1 into @emp
end

close rsf1
deallocate rsf1"
   

- Advertisement -