自动生成单号
格式如下:
比如是询价单
XJD20110630001
字母+年月日+3位数
后面那个三位数要自增,从001开始自增,当年月日的日改变时,则那三位数又从001开始自增
格式如下:
比如是询价单
XJD20110630001
字母+年月日+3位数
后面那个三位数要自增,从001开始自增,当年月日的日改变时,则那三位数又从001开始自增
解决方案 »
- 如何session的值赋到label的text属性上
- int成员变量的困惑
- WIN7 Web 服务器上似乎未安装 FrontPage 服务器扩展
- asp.net连接mysq数据库的代码
- 100分不够,再加100分。高手请进入
- 使用application对象存储一个订单类的实例(有几万条记录的话),会不会有什么问题??
- 为什么强类型的表对象不能放到ViewState而普通的表对象却可以放进去?
- 不能创建WEB项目这是什么原因??
- 有关DataGrid 的分页和显示当前页的问题
- 選擇select1時select2的值要跟著改變????送100分!
- 散分(C#网银接口。Error:500)
- .net Access数据库连接问题
@orderID nvarchar(50) output
as
BEGIN
declare @date datetime
declare @year nvarchar(4)
declare @month nvarchar(2)
declare @day nvarchar(2)
declare @hour nvarchar(2)
declare @min nvarchar(2)
declare @randNum int
set @date=getdate()
set @year=DATEPART(yyyy,@date)
set @month=right(cast(power(10,3) as nvarchar)+DATEPART(mm,@date),2)
set @day=right(cast(power(10,2) as nvarchar)+DATEPART(d,@date),2)
set @hour=right(cast(power(10,2) as nvarchar)+DATEPART(hh,@date),2)
set @min=right(cast(power(10,2) as nvarchar)+DATEPART(mi,@date),2)
set @randNum=cast(floor(rand()*1000000) as int)
set @orderID=@year + @month+ @day + @hour + @min + right(cast(power(10,6) as nvarchar)+convert(nvarchar(6),@randNum),6)
begin
set @randNum=cast(floor(rand()*10000) as int)
set @orderID =@year + @month+ @day + @hour + @min + right(cast(power(10,6) as nvarchar)+convert(nvarchar(6),@randNum),6)
end
END
具体的你在做条件判断一下
@VNEWID VARCHAR(16) OUTPUT
AS
BEGIN
DECLARE @DATE DATETIME
DECLARE @YYYY VARCHAR(4)
DECLARE @MM VARCHAR(2)
DECLARE @DD VARCHAR(2)
--保存取得的当前时间
SET @DATE = GETDATE()
SET @YYYY = DATEPART(yyyy, @DATE)
SET @MM = DATEPART(mm, @DATE)
SET @DD = DATEPART(dd, @DATE)
--位数不够的前面补0
SET @YYYY = REPLICATE('0', 4 - LEN(@YYYY)) + @YYYY
SET @MM = REPLICATE('0', 2 - LEN(@MM)) + @MM
SET @DD = REPLICATE('0', 2 - LEN(@DD)) + @DD --取出表中当前日期的已有的最大ID
SET @VNEWID = NULL
SELECT TOP 1 @VNEWID = [LID] FROM [VT_TableName] WHERE [LID] LIKE @YYYY+@MM+@DD+'%' ORDER BY [LID] DESC
--如果未取出来
IF @VNEWID IS NULL
--说明还没有当前日期的编号,则直接从1开始编号,日期后面是八位数字,可以根据需要调整位数.
SET @NEW_ID = (@YYYY+@MM+@DD+'00000001')
--如果取出来了
ELSE
BEGIN
DECLARE @NUM VARCHAR(8)
--取出最大的编号加上1
SET @NUM = CONVERT(VARCHAR, (CONVERT(INT, RIGHT(@NEW_ID, 8)) + 1))
--因为经过类型转换,丢失了高位的0,需要补上
SET @NUM = REPLICATE('0', 8 - LEN(@NUM)) + @NUM
--最后返回日期加编号
SET @VNEWID = @YYYY+@MM+@DD + @NUM
END
END
GO--调用方式:执行5次调用及插入数据测试
DECLARE @N INT
SET @N = 0
WHILE @N < 5
BEGIN
DECLARE @VNEWID VARCHAR(16)
EXECUTE VP_GetNewID @VNEWID OUTPUT
INSERT INTO [VT_TestTableName] ([LID]) VALUES (@VNEWID)
SET @N = @N + 1
END
GO
USE [dqERP]
GO
/****** Object: StoredProcedure [dbo].[sp_PayCheck] Script Date: 07/03/2011 13:15:47 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[sp_PayCheck](@Date DateTime)
asdeclare @LastDate datetime,
@LastYear int,
@LastMonth int,
@CheckMonth varchar(6),
@ThisMonth varchar(6),
@dStart datetime,
@iYear int,
@iMonth int,
@sMonth varchar(6),
@Month varchar(6),
@sValue varchar(6)select @LastDate = dateadd(month,-1,@Date)select @LastYear = year(@LastDate),@LastMonth = month(@LastDate)select @CheckMonth = cast(@LastYear as varchar(4))+right('0'+cast(@LastMonth as varchar(2)),2)select @iYear = year(@Date),@iMonth = month(@Date)select @ThisMonth = cast(@iYear as varchar(4))+right('0'+cast(@iMonth as varchar(2)),2)insert into t_PayCheck
select @ThisMonth,F_SupplierID,sum(F_Money)
from
(
select F_SupplierID,F_Money from t_PayCheck
where F_Month = @CheckMonth
union all
select F_SupplierID,sum(F_Money) from t_StockIn
where year(F_Date) = year(@Date)
and month(F_Date) = month(@Date)
group by F_SupplierID
union all
select F_SupplierID,-sum(F_Money) from t_Pay
where year(F_Date) = year(@Date)
and month(F_Date) = month(@Date)
group by F_SupplierID
) as tp
group by F_SupplierID