当前位置:主页>销售管理软件> 列表

急求一存儲過程(單據編號) 找汽车维修管理软件

销售管理软件版1楼: 上司要求單據的編號形式如下:
(即格式: 四位年+两位月+两位日+四位流水号,其中流水號每日都要從0001開始)
200602140001
200602140002
200602140003
。。。。
200602150001
200602150002
。。。。

2楼: 用代码不行吗 如人事管理软件

3楼: declare @MaxID Char(12),@Date Char(8)

set @Date = convert(Char(8),GetDate(),112)

select @MaxID = Max(流水号) from 表 where left(流水号,8) = @Date

if @maxID is null

insert into 表 (流水号) values (@Date+''0001'')

else

set @MaxID = Cast((Cast(@MaxID as Int) + 1) as Char(12))

insert into 表 (流水号) values (@MaxID)

4楼: 学习中

5楼: CREATE PROCEDURE [單據編號] -- 在我本機上測試通過,數據表修改為你自己的就行了。
AS
declare @MaxID Char(12),@Date Char(8),@s varchar(3),@n varchar(4)
set @Date = convert(Char(8),GetDate(),112)
select @MaxID = Max(UserPass) from Table1 where left(UserPass,8) = @Date


if @maxID=''''
insert into Table1 (UserPass) values (@Date+''0001'')
else
begin
set @n=Cast((Cast(substring(@MaxID,9,13) as Int) + 1) as Char(12))
If Len(@n) = 1
Set @s=''000''
If Len(@n) = 2
Set @s=''00''
If Len(@n) = 3
Set @s=''0''
if Len(@n) > 3
Set @s=''''
set @MaxID = substring(@MaxID,1,8)+@s+@n
end
if @maxID<>''''
insert into Table1 (UserPass) values (@MaxID)
GO

6楼: 學習中,bbscom,怎麼table1老是插入null值,
我這測試不能通過啊?

销售管理软件版7楼: 这么简单的都不会,你公司花钱请你做什么呀?
说笑的,别生气。。。

8楼: to 康仔

if @maxID='''' 改成 if @maxID is null 就好了!

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

ALTER PROCEDURE [單據編號] -- 在我本機上測試通過,數據表修改為你自己的就行了。
AS
declare @MaxID Char(12),@Date Char(8),@s varchar(3),@n varchar(4)
set @Date = convert(Char(8),GetDate(),112)
select @MaxID = Max(UserPass) from Table1 where left(UserPass,8) = @Date


if @maxID is null
insert into Table1 (UserPass) values (@Date+''0001'')
else
begin
set @n=Cast((Cast(substring(@MaxID,9,13) as Int) + 1) as Char(12))
If Len(@n) = 1
Set @s=''000''
If Len(@n) = 2
Set @s=''00''
If Len(@n) = 3
Set @s=''0''
if Len(@n) > 3
Set @s=''''
set @MaxID = substring(@MaxID,1,8)+@s+@n
end
if @maxID<>''''
insert into Table1 (UserPass) values (@MaxID)

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

9楼: 说明:
档案号的格式: 四位年+两位月+两位日+四位档案号
即:200202260001
档案编号表:记录当前最新的档案编号,只有一个记录.为了防止记录 出现重复的情况.
CREATE PROCEDURE prGetNo --产生按年月日排列的档案号
@No varchar(12) output ---为产生的档案号
AS
declare @Year Int,
@Month int,
@Day int,
@Temp_No varchar(12),
@NeedNo varchar(4) --档案号
BEGIN
select @year=Year(GetDate())
select @Month=Month(GetDate())


select @Day=Day(GetDate())
select @No=Str(@Year,4,0)+
(select
case
when @Month>=10 then Str(@Month,2,0)
when @Month<10 Then ''0''+Str(@Month,1,0)
end)+
(select
case
when @Day>=10 then Str(@Day,2,0)
when @Day<10 Then ''0''+Str(@Day,1,0)
end)
SELECT @Temp_No = 档案编号 FROM 档案编号表
IF @No <> SUBSTRING( @Temp_No,1,8)
SELECT @No = @No+''0001''
ELSE
BEGIN
SELECT @RandNo = STR(CONVERT(int,(SUBSTRING( @Temp_No ,9,4))+1),4,0)
SELECT @RandNo = REPLACE( @RandNo,'' '',''0'')
SELECT @No = @No + @RandNo
END
UPDATE 档案编号表
SET 档案编号 = @No
END
END

10楼: 修改我寫的代碼如下:
就可以正確使用了。
CREATE PROCEDURE [單據編號] -- 在我本機上測試通過,數據表修改為你自己的就行了。
AS
declare @MaxID Char(12),@Date Char(8),@s varchar(3),@n varchar(4)
set @Date = convert(Char(8),GetDate(),112)
select @MaxID = Max(UserPass) from Table1 where left(UserPass,8) = @Date
if @MaxID is null -- 這個地方修改了
insert into Table1 (UserPass) values (@Date+''0001'')
else
begin
set @n=Cast((Cast(substring(@MaxID,9,13) as Int) + 1) as Char(12))
If Len(@n) = 1
Set @s=''000''
If Len(@n) = 2
Set @s=''00''
If Len(@n) = 3
Set @s=''0''
if Len(@n) > 3
Set @s=''''
set @MaxID = substring(@MaxID,1,8)+@s+@n
end
if not (@MaxID is null) -- 這個地方修改了
insert into Table1 (UserPass) values (@MaxID)
GO

11楼: 很多謝各位的指點,
對於這個功能我知道已經有很多前輩實現了
那我就沒必要再想,想出來的不一定能比前輩的好
我只想在系統的分析、系統架構上花多點力氣
而且,我也實現了“代碼重用”啊^-^
再次多謝各位,多謝。。

12楼: bbscom,我會記住你的! 如汽车维修管理软件

13楼: ugvanxk,多謝你