如何找到丢失的号码?

编程入门 行业动态 更新时间:2024-10-24 06:34:34
本文介绍了如何找到丢失的号码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在桌子上找到丢失的号码。表格就像这样。

Sno Branch 1 ABC 2 ABC 3 ABC 5 ABC // 缺少第4个sno 6 ABC 8 ABC // 缺少第7个sno 10 ABC // 第9个sno缺失

我发现使用此查询丢失的SNO

ALTER proc [dbo]。[K_RT_DCNoMissing] - 1,50 as 开始 声明 @id int set @id = 0 声明 @maxid int - 设置@id = @fromvalue 选择 @ maxid =(选择 count(*)dcno 来自 K_RT_Dailyentryretail 否锁 ) 创建 表 #IDSeq ( id int ) while 0< @maxid - 无论您的最大值是 开始 插入 进入 #IDSeq 值( @ id ) set @ id = @ id + 1 set @ maxid = @ maxid - 1 - print @maxid end 选择 s。 id - ,(选择wd.branch来自K.RT_Dailyentryretail d内部联接K_RT_WarehouseDetails wd on d.branchdate = wd .sno,其中d.dcno不为null)作为分支 来自 #idseq s left join K_RT_Dailyentryretail t s.id = t.dcno 其中 t.dcno null order by s.id asc drop table #IDSeq end

我这样就出去了..

MissingNo ' s 4 7 9

现在我想显示与分支名称相似的Sno。

MissingNo ' s Branch 4 ABC 7 ABC 9 ABC

如何获得分行名称......

解决方案

你想从表中找到Missing No。如果检查我的下面的查询,我已经创建了一个样本你。

- 我为你创建了一个样本表 create table K_RT_Dailyentryretail( SNO int 不 null primary key ,分支 varchar ( 10 )); - 此处将样本数据插入表中,缺少编号 insert into K_RT_Dailyentryretail(SNO,Branch) values ( 1 ,' ABC'),( 2 ,' ABC'),( 3 ,' ABC'),( 5 ,' ABC'),( 6 ,' ABC'),( 8 ,' ABC'),( 10 ,' ABC') - select * from K_RT_Dailyentryretail - 以下是仅从给定表中选择缺少的No的查询。 选择 KRD.SNO + 1 as MissingNos 来自 K_RT_Dailyentryretail as KRD left 外部 join K_RT_Dailyentryretail as LKRD on KRD.SNO + 1 = LKRD.SNO 其中 LKRD.SNO null

我看不出你怎么做,除非表格中的所有行拥有相同的分支。

SELECT DISTINCT 分支 FROM K_RT_Dailyentryretail;

但我认为很可能不是这种情况。 删除行,对吧?那么从何处获取信息? 一个选项可能是添加一个名为Status的列,其值为Active / Inactive而不是删除行,您可以更改状态。 另一种选择是将已删除的行存储在自己的表中。

声明 @ id int set @ id = 0 声明 @ maxid int - set @id = @fromvalue 选择 @ maxid =( select count(*)dcno 来自 K_RT_Dailyentryretail nolock ) PRINT @ maxid 创建 表 #IDSeq ( id int ) while 0< @maxid - 无论您的最大值是什么 开始 插入 进入 #IDSeq values ( @ id ) set @ id = @ id + 1 set @ maxid = @ maxid - 1 - print @maxid end 创建 table #MissingNumbers ( id int , BRANCH VARCHAR (MAX)) INSERT INTO #MissingNumbers(id) 选择 s.id 来自 #idseq s left join K_RT_Dailyentryretail t on s.id = t.dcno 其中 t。 dcno null order by s.id asc DECLARE @ count INT =( SELECT MAX(id) FROM #MissingNumbers)/ 50 DECLARE @ value INT = 1 while @ value< = @ count - 无论你有什么最大值 开始 更新 #MissingNumbers SET BRANCH =( SELECT TOP 1 BRANCH FROM K_RT_Dailyentryretail WHERE dcno BETWEEN (( @ value-1 )* 50) AND (@ value * 50)) WHERE id IN ( SELECT id FROM #MissingNumbers 其中 id BETWEEN (( @ value-1 )* 50) AND (@ value * 50)) set @ value = @ value + 1 - print @ maxid end SELECT * FROM #MissingNumbers drop t能够 #IDSeq drop table #MissingNumbers

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 --,(select wd.branch from K_RT_Dailyentryretail d inner join K_RT_WarehouseDetails wd on d.branchdate=wd.sno where d.dcno is not null) as branch 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...

解决方案

Hi, Do you want to find the Missing No from a Table .If so check my below query i have created a sample for you.

-- I have created a Sample Table for you create table K_RT_Dailyentryretail ( SNO int not null primary key, Branch varchar(10) ); -- here insert sample data to the table with missing no. insert into K_RT_Dailyentryretail (SNO,Branch) values (1,'ABC'), (2,'ABC'), (3,'ABC'), (5,'ABC'), (6,'ABC'), (8,'ABC'), (10,'ABC') --select * from K_RT_Dailyentryretail -- Here is the query to select only the missing No from the given table. select KRD.SNO + 1 as MissingNos from K_RT_Dailyentryretail as KRD left outer join K_RT_Dailyentryretail as LKRD on KRD.SNO + 1 = LKRD.SNO where LKRD.SNO is null

I can't see how you can do that, unless all rows in the table have the same Branch.

SELECT DISTINCT Branch FROM K_RT_Dailyentryretail;

But that is most likely not the case, I would presume. The rows are deleted, right? So where to get the info? One option could be to add a column called Status that has the values Active/Inactive and instead of deleting the row, you change the status. Another option is to store deleted rows in its own table.

declare @id int set @id = 0 declare @maxid int --set @id = @fromvalue select @maxid = (select count(*) dcno from K_RT_Dailyentryretail nolock ) PRINT @maxid 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 create table #MissingNumbers ( id int, BRANCH VARCHAR(MAX) ) INSERT INTO #MissingNumbers(id) 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 DECLARE @count INT = (SELECT MAX(id) FROM #MissingNumbers)/50 DECLARE @value INT = 1 while @value<=@count--whatever you max is begin UPDATE #MissingNumbers SET BRANCH = (SELECT TOP 1 BRANCH FROM K_RT_Dailyentryretail WHERE dcno BETWEEN ((@value-1)*50) AND (@value*50)) WHERE id IN (SELECT id FROM #MissingNumbers where id BETWEEN ((@value-1)*50) AND (@value*50)) set @value= @value + 1 -- print @maxid end SELECT * FROM #MissingNumbers drop table #IDSeq drop table #MissingNumbers

更多推荐

如何找到丢失的号码?

本文发布于:2023-11-30 21:06:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1651471.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:号码

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!