I want to find Missing Numbers in a table..Table Like this.
Sno Branch
1 ABC
2 ABC
3 ABC
5 ABC // 4th sno is missing
6 ABC
8 ABC // 7th sno is missing
10 ABC // 9th sno is missing
I found the missing SNo using this Query
ALTER proc [dbo].[K_RT_DCNoMissing]--1,50
as
begin
declare @id int
set @id = 0
declare @maxid int
--set @id = @fromvalue
select @maxid = (select count(*) dcno from K_RT_Dailyentryretail nolock)
create table #IDSeq
(
id int
)
while 0<@maxid--whatever you max is
begin
insert into #IDSeq values(@id)
set @id = @id + 1
set @maxid = @maxid - 1
-- print @maxid
end
select
s.id
from
#idseq s
left join K_RT_Dailyentryretail t on
s.id = t.dcno
where t.dcno is null order by s.id asc
drop table #IDSeq
end
I am getting out put like this..
MissingNo's
4
7
9
Now I want to Display Sno with Branch Name like.
MissingNo's Branch
4 ABC
7 ABC
9 ABC
How can i get the branch name...
Am getting output as
4 abc
4 cde
4 fgh
7 abc
7 cde
7 fgh
but what actually am expecting is
4 abc
7 cde
. ..
. ..
etc.