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)
 How to obtain the next free value of a column?

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-11-03 : 07:49:10
Anthony Laportta writes "Hi

I am triying to obtain the next free value of a column in a table with a SQL.

For example supose that the table is T1 and de column C1

C1
--
1
2
4
5
7

The result in this case must be 3.

The following SQL program works fine but it is very slow.
Do you know another solution?


select bb
from (
select x as aa,count(y) as bb
from (
select a.C1 as x,b.C1 as y
from T1 a, T1 b
where a.C1 >= b.C1
group by a.C1,b.C1
) vista1
group by x
) vista2
where aa<>bb
limit 1


Bye and thanks in advance

Anthony Laportta"

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2003-11-03 : 08:10:42
select top 1 * from customer a
left join customer b
on a.code = b.code + 1
where b.code is null
order by a.code
Go to Top of Page
   

- Advertisement -