我在表中有一单号字段,怎样显示出中间没有用的单号?请进来看详细内容。谢谢!

Angelnet 2003-12-16 05:12:33
我有一单号字段:如下
单号
WL0001
WL0002
WL0004
RP0001
RP0002
RP0003
RP0006

其中 单号列少了WL0003 RP0004 RP0005
这样就表示销售人员漏单,我怎么样找出漏的这些单?非常感谢!
...全文
74 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Angelnet 2003-12-16
  • 打赏
  • 举报
回复
zjcxc(邹建) 我发觉你太恐怖了,我去试试,谢谢!
也谢谢大家!
gmlxf 2003-12-16
  • 打赏
  • 举报
回复
要想找出WL0003 RP0004 RP0005这样的号码难度有点吧。

select left(单号,2) + cast((right(a.单号,4)-1) as varchar) 单号 from table a
where not exists (select 1 from table where right(单号,4)=right(a.单号,4)-1)
order by 单号

不过这样找出来是部分,不全。
zjcxc 元老 2003-12-16
  • 打赏
  • 举报
回复
--测试表
create table 表(单号 varchar(10))
insert into 表
select 'WL0001'
union all select 'WL0002'
union all select 'WL0004'
union all select 'RP0001'
union all select 'RP0002'
union all select 'RP0003'
union all select 'RP0006'
go

--得到编号缺号的字符列表
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_getNseries]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[f_getNseries]
GO

create function f_getNseries(@head varchar(10))
returns varchar(8000)
as
begin
declare @re varchar(8000),@id int,@h varchar(10)
select @re='',@id=0,@h=@head+'%'
select @re=case @id when id-1 then @re
else @re+','+@head+right('0000'+cast(@id+1 as varchar),4)
+case @id+1 when id-1 then ''
else '-'+@head+right('0000'+cast(id-1 as varchar),4) end
end
,@id=id
from (select id=cast(right(单号,4) as int) from 表 where 单号 like @h) a
set @re=substring(@re,2,8000)
return(@re)
end
go

--调用实现你的要求
select dbo.f_getNseries(aa) from(
select distinct aa=left(单号,2) from 表
) a

go
drop table 表

/*--测试结果
-------------------
RP0004-RP0005
WL0003

(所影响的行数为 2 行)

--*/
zjcxc 元老 2003-12-16
  • 打赏
  • 举报
回复
--函数再改一下:
--得到编号缺号的字符列表
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_getNseries]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[f_getNseries]
GO

create function f_getNseries(@head varchar(10))
returns varchar(8000)
as
begin
declare @re varchar(8000),@id int,@h varchar(10)
select @re='',@id=0,@h=@head+'%'
select @re=case @id when id-1 then @re
else @re+','+@head+right('0000'+cast(@id+1 as varchar),4)
+case @id+1 when id-1 then ''
else '-'+@head+right('0000'+cast(id-1 as varchar),4) end
end
,@id=id
from (select id=cast(right(单号,4) as int) from 表 where 单号 like @h) a
set @re=substring(@re,2,8000)
return(@re)
end
go
zjcxc 元老 2003-12-16
  • 打赏
  • 举报
回复
--得到编号缺号的字符列表
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_getNseries]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[f_getNseries]
GO

create function f_getNseries(@head varchar(10))
returns varchar(8000)
as
begin
declare @re varchar(8000),@id int
select @re='',@id=0,@head=@head+'%'
select @re=case @id when id-1 then @re
else @re+','+cast(@id+1 as varchar)
+case @id+1 when id-1 then ''
else '-'+cast(id-1 as varchar) end
end
,@id=id
from (select id=cast(right(单号,4) as int) from 表 where 单号 like @head) a
set @re=substring(@re,2,8000)
return(@re)
end
go

--调用实现你的要求
select dbo.f_getNseries(aa) from(
select distinct aa=left(单号,2) from 表
) a
victorycyz 2003-12-16
  • 打赏
  • 举报
回复
declare @m int

create table #t (id,int)
select @m=max(cast(right(单号,4) as int)) from tablename
while @m>0
begin
insert into #t values (@m)
@m=@m-1
end

select a.id
from #t a left join
tablename b
on a.id=cast(right(单号,4) as int)
where b.单号 is null

drop table #t
realgz 2003-12-16
  • 打赏
  • 举报
回复
select * from table
where not exists (select 1 from table t where abs(right(t.单号,4)-right(table.单号,4))=1)
order by 单号
realgz 2003-12-16
  • 打赏
  • 举报
回复
给区间可以吧?
select * from table
where not exists (select 1 from table t where abs(right(t.单号)-table.单号)=1)
order by 单号
该系统分5个模块,功能分别为: 一.人员档案的管理、物料档案管理 设计实现对企业人员基本情况的档案的输入、删除与修改,企业人员基本情况主要包括:人员代码、姓名、性别、生日期、身份证、籍贯、家庭住址、联系电话、其它情况等(对身份证,电话码合法性验证)。 物料档案包括物料代码、物料名称、规格型、计量单位、库存数量、备注等字段。 1. 物料档案的增加、修改、删除程序,客户端输入时要求物料代码不为空,计量单位可以选择“件、套、公斤、吨、升、米、毫米、个”等,计量单位并可以输入其它单位名,库存数量默认为0。 2. 物料查询程序可以在通过输入框的文字进行模糊查询(物料代码、名称、规格中是否含有输入框的文字). 二. 简单物料进仓/仓信息管理 企业物料进仓的信息管理,物料进仓的信息主要包括进、进仓日期、操作人员代码、备注、物料代码、进仓数量、仓数量等 1. 企业仓库进仓信息表可以用一个表,也可以用二个表(一对多关系),具体表设计的思路须在报告中描述。 2. 进仓程序与仓程序可以合并,也可以分开做。其中操作人员用下拉框来选择;要自己编规则自动生成,产生规则在报告中说明;进仓日期用日期控件;物料代码下拉框做选择;当物料仓时判断仓数量时候超过物料的库存数量,物料的库存数量在物料表中可以获得该物料的库存数量。进行进仓或仓操作时通过调用存储过程来实现,存储过程将操作结果返回调用者,显示成功或失败的信息。 3. 进仓、仓的存储过程可以合并或分开做,存储过程要判断物料是否存在,操作后物料库存数量是否不为负数;如果不满足条件显示,失败提示;如果满足条件,增加进仓表记录一条,并根据进仓物料的数量对物料表中库存数量进行修改,提交数据库操作,否则回滚。 4. 进仓单查询程序,可以用进仓日期起止条件,物料代码、操作人员、备注(用子串查询)来完成。 三、多物料进仓信息管理 一般企业进行物料进仓时,多在一个进上同时对多种物料做同进或同操作,通过程序实现多个物料在一个界面一个上同时实现进仓或仓操作,如果不成功,必须全部回滚。 1. 多物料进仓仓,可以在一个程序中完成,也可以分开编程,同一中进、进仓日期、操作人员必须完全相同,同一中不能进仓与仓同时存在,通过调用存储过程完成进仓操作。 2. 多物料进仓存储过程,多物料进仓单增加到表中,并修改多个物料的库存数量,失败就显示提示内容。 四、用户登录与权限设计 用户在这里就指操作人员,已经在人员档案中进行管理,通过设计用户登录和用户权限的管理,实现用户按权限访问资源,管理员按要求授予用户权限,登录程序安全稳定,设计用户菜单及程序调用。人员表中需要新增字段口令、用户权限。系统中每个操作人员都可以作为用户,当一个用户权限修改时,不会影响其他用户;可以对每个用户单独授予某个程序的执行权,也可以收回其执行权,而不影响其他用户的权限; 1. 用户登录程序,输入用户名和口令,判断正确后,按用户的权限,显示有权的菜单项,无权菜单项必须不可见或不可操作。 2. 用户授权程序。有授权权限的用户,可以指定某个用户获取某个程序执行权,或被禁止某个程序的执行权。 五、统计程序设计与报表打印 按物料统计进仓流量,计算分析流动量最小的物料。按月份打印进仓单表,打印进仓单,按物料打印仓库账本。 1. 物料统计程序,统计各物料在指定时间内的进仓数量总数,用图形显示。 2. 打印进仓单程序,给定月份,将该月进仓单全部按顺序打印来。 3. 打印仓库账本程序,给定年份和物料,打印物料代码、名称、规格、计量单位、各日期的进仓、仓和库存量。 资源包含: 1.系统源码 2.数据库及脚本 3.部分1详细说明报告 4.部分2详细说明报告 5.部分3详细说明报告 6.部分4详细说明报告 7.部分5详细说明报告 8.系统总说明

34,837

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧