设计sql编号,要求每添加一条数据,自动给改数据添加一个编号
一种是现金,一种是刷卡。2种结算方式有2种收款单。现金方式时单据编号:sk-000-2011-01-15-00001,其中“2011-01-15”为系统当前日期。刷卡结算...
一种是现金,一种是刷卡。2种结算方式有2种收款单。现金方式时单据编号:sk-000-2011-01-15-00001,其中“2011-01-15”为系统当前日期。刷卡结算单据编号:sk-001-2011-01-15-00001,其中“2011-01-15”为系统当前日期。
如何用sql语句实现。
实在是没有分数了
declare @haoma nvarchar(50)
set @haoma=''
if @leixing='现金'
begin
select
case when A.编号 is null then 'sk-000-'+cast(year(getdate()) as nvarchar)+'-'+cast(month(getdate()) as nvarchar)+'-'+cast(day(getdate()) as nvarchar)+'-00001'
else 'sk-000-'+cast(year(getdate()) as nvarchar)+'-'+cast(month(getdate()) as nvarchar)+'-'+cast(day(getdate()) as nvarchar)+'-'+cast(A.编号 as nvarchar)
end
as 编号
from (select right('00000'+cast(cast(right(max(单据编号),5) as int)+1 as nvarchar),5) as 编号 from 本班收款交费记录 where 单据编号 like 'sk-000%') as A
end
end
select @haoma as 单据编号 展开
如何用sql语句实现。
实在是没有分数了
declare @haoma nvarchar(50)
set @haoma=''
if @leixing='现金'
begin
select
case when A.编号 is null then 'sk-000-'+cast(year(getdate()) as nvarchar)+'-'+cast(month(getdate()) as nvarchar)+'-'+cast(day(getdate()) as nvarchar)+'-00001'
else 'sk-000-'+cast(year(getdate()) as nvarchar)+'-'+cast(month(getdate()) as nvarchar)+'-'+cast(day(getdate()) as nvarchar)+'-'+cast(A.编号 as nvarchar)
end
as 编号
from (select right('00000'+cast(cast(right(max(单据编号),5) as int)+1 as nvarchar),5) as 编号 from 本班收款交费记录 where 单据编号 like 'sk-000%') as A
end
end
select @haoma as 单据编号 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询