比如今天是2010年01月30号,那么这{yt}生成的订单:
{dy}张订单:dj201001300001;
第二张订单:dj201001300002;
第三张订单:dj201001300003;
到了第二天就是是2010年01月31号,那么这{yt}生成的订单:
{dy}张订单:dj201001310001;
第二张订单:dj201001310002;
第三张订单:dj201001310003;
解决方法如下:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER
trigger
[dbo].[tg_insert]
on
[dbo].[TCaiGou]
for
insert
as
declare
@ID
INT
declare
@DDid
varchar(20)
declare
@num
int
select
@DDid=max(DDid)
from
TCaiGou
where
DDid
like
'dj'
+
substring(convert(varchar(10),getdate(),112),0,8)
+
'%'
if
@DDid
is
null
set
@DDid='dj'
+
substring(convert(varchar(10),getdate(),112),0,8)
+
'01'
else
begin
set
@num=cast(substring(@DDid,10,2)
as
int)
set
@num=@num
+
1
if
@num<10
set
@DDid='dj'
+
substring(convert(varchar(10),getdate(),112),0,8)
+
'0'
+
cast(@num
as
varchar(2))
else
set
@DDid='dj'
+
substring(convert(varchar(10),getdate(),112),0,8)
+
''
+
cast(@num
as
varchar(2))
end
SElect @ID=ID from inserted
Update TCaiGou Set where