Declare @maxVersion int,@strYear varchar(2),@strMonth varchar(2),@strYearMonth varchar(4)
Set @strYear = Right(Cast(Datepart(yy,Getdate()) AS varchar(4)),2)
Set @strMonth = Cast(Datepart(mm,Getdate()) AS varchar(4))
if (Len(@strMonth) = 1)
Set @strMonth = '0' + @strMonth
Set @strYearMonth = @strYear + @strMonth
select @maxVersion = max(BomVersion) from TBL_Bom Where MaterialNo = @MaterialNo
--当最大值无效,或当前月份有大于最大值月份时
if (@maxVersion is null OR @maxVersion = 0 OR Cast(@strYearMonth AS Int) > @maxVersion / 100)
set @BomNewVersion = Cast( (@strYearMonth + '01') AS int)
else
Set @BomNewVersion = @maxVersion + 1
三个SUBSTRING
Sql server 中 SELECT x = SUBSTRING('abcdef', 1,len('abcdef'))
c# 中: string x = SUBSTRING('abcdef', 0,len('abcdef'))
javascript中:string x = SUBSTR('abcdef', 0,len('abcdef'))
稍微有点区别。
Set @strYear = Right(Cast(Datepart(yy,Getdate()) AS varchar(4)),2)
Set @strMonth = Cast(Datepart(mm,Getdate()) AS varchar(4))
if (Len(@strMonth) = 1)
Set @strMonth = '0' + @strMonth
Set @strYearMonth = @strYear + @strMonth
select @maxVersion = max(BomVersion) from TBL_Bom Where MaterialNo = @MaterialNo
--当最大值无效,或当前月份有大于最大值月份时
if (@maxVersion is null OR @maxVersion = 0 OR Cast(@strYearMonth AS Int) > @maxVersion / 100)
set @BomNewVersion = Cast( (@strYearMonth + '01') AS int)
else
Set @BomNewVersion = @maxVersion + 1
三个SUBSTRING
Sql server 中 SELECT x = SUBSTRING('abcdef', 1,len('abcdef'))
c# 中: string x = SUBSTRING('abcdef', 0,len('abcdef'))
javascript中:string x = SUBSTR('abcdef', 0,len('abcdef'))
稍微有点区别。