Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
select ID+1 from Table t1
where not exists (select 1 from Table t2
where t2.ID+1 = t1.ID)
AND ID < (select max(ID) from Table)
select [block id]+1 from Table #TmpLergConvert
where not exists (select 1 from Table t2
where t2.ID+1 = t1.ID)
AND ID < (select max(ID) from Table)
Col02 Col02 Col03 Col04 Col05 Col06
566 210 478 0 6671 TX
566 210 478 1 6671 TX
566 210 478 2 6671 TX
566 210 478 3 9533 TX
566 210 478 4 9533 TX
566 210 478 6 6671 TX
566 210 478 7 6671 TX
566 210 478 8 6671 TX
566 210 478 9 6671 TX
566 210 478 A 9533 TX
"I liked my solution better..."
select Col02 , Col03, Col04+1 as Col04
into #tmp
from #TmpLergConvert t1
where not exists (select 1 #TmpLergConvert t2
where t2.Col02 = t1.Col02
AND t2.Col03 = t1.Col03
AND t2.Col04+1 = t1.Col04)
AND ID < 9 and id <> 'A'
select Col02 , Col03, min(Col04) as min
into #tmp2
from #tmp
group by Col02 , Col03
update #TmpLergConvert
SET Col04 = t2.Col04
from #TmpLergConvert t1, #tmp2 t2
where t2.Col02 = t1.Col02
AND t2.Col03 = t1.Col03
AND t1.ID = 'A'
select Col02 , Col03, Col04+1 as Col04
into #tmp
from #TmpLergConvert t1
where not exists (select 1 #TmpLergConvert t2
where t2.Col02 = t1.Col02
AND t2.Col03 = t1.Col03
AND t2.Col04+1 = t1.Col04)
AND ID < 9 and id <> 'A'
select Col02 , Col03, Col04+1 as Col04
into #tmp
from #TmpLergConvert t1
where not exists (select 1 #TmpLergConvert t2
where t2.Col02 = t1.Col02
AND t2.Col03 = t1.Col03
AND t2.Col04+1 = t1.Col04)
AND t1.Col04 < '9' and t1.Col04 <> 'A'
select Col02 , Col03, min(Col04) as min
into #tmp2
from #tmp
group by Col02 , Col03
update #TmpLergConvert
SET Col04 = t2.Col04
from #TmpLergConvert t1, #tmp2 t2
where t2.Col02 = t1.Col02
AND t2.Col03 = t1.Col03
AND t1.Col04 = 'A'
I don't understand what you mean by this: I'm sorry, generally I wouldn't "talk" like that - but in this caseMicha123 said:SQLBill,
I'm sorry, generally I wouldn't "talk" like that - but in this case:
Quote:
"I liked my solution better..."
SELECT NPA , NXX, BlockId+1 AS BlockID
INTO #tmp
FROM #TmpLergConvert t1
WHERE not exists (SELECT 1 FROM #TmpLergConvert t2
WHERE t2.NPA = t1.NPA
AND t2.NXX = t1.NXX
AND t2.Blockid+1 = t1.Blockid)
AND t1.Blockid < '9' and t1.BlockId <> 'A'
Server: Msg 245, Level 16, State 1, Line 1
Syntax error converting the varchar value 'A' to a column of data type int.