CREATE PROCEDURE dbo.GetRepairBillID;1
@id int output
AS
declare @curtime int
BEGIN
select @curtime = CONVERT(int , GETDATE(), 12)
if exists(select * from RepairBill where ID > @curtime *100 and ID < (@curtime*100+99) )
select @id = max(ID) + 1 from RepairBill where ID > @curtime *100 and ID < (@curtime*100+99)
else
select @id = @curtime*100 + 1
ENDSQL语句如上。大体流程是我想获得一个ID 这个ID是当天的日期加2为个数ID。比如2010082701就是2010年8月27日的第一个ID,如果程序调用GetRepairBillID则变成2010082702。现在不知道CONVERT函数可以吧日期变成int类型的吗?还有SQL中有long这个数据类型吗?我使用后报错。最后问下这种存储过程如何调试啊 又加不了断点。
(PS 编译环境为VC6.0 +SYBASE12.5.1)
@id int output
AS
declare @curtime int
BEGIN
select @curtime = CONVERT(int , GETDATE(), 12)
if exists(select * from RepairBill where ID > @curtime *100 and ID < (@curtime*100+99) )
select @id = max(ID) + 1 from RepairBill where ID > @curtime *100 and ID < (@curtime*100+99)
else
select @id = @curtime*100 + 1
ENDSQL语句如上。大体流程是我想获得一个ID 这个ID是当天的日期加2为个数ID。比如2010082701就是2010年8月27日的第一个ID,如果程序调用GetRepairBillID则变成2010082702。现在不知道CONVERT函数可以吧日期变成int类型的吗?还有SQL中有long这个数据类型吗?我使用后报错。最后问下这种存储过程如何调试啊 又加不了断点。
(PS 编译环境为VC6.0 +SYBASE12.5.1)
解决方案 »
- 第二次发问:已知列名列表,如何查找含有这些列的表
- 求推荐ORACLE相关书籍谢谢....
- 更新问题
- 急Asql2000个人版,我进数据库企业管理器的时候第一次能进,我要是关了再进,就在那卡着,然后提示超时。
- 执行目录下的所有存储过程
- 一表有两个字段,其中一个是自增字段,一个是Image类型,如何在存储过程中INSERT记录后就可以知道这个自增字段的值?
- 急!安装SQL2000时,一个奇怪的问题!
- 怎样将RECORDSET里面的数据直接INSERT进表里面去,不考虑将RECORDSET的数据取出来再处理!
- 如何把SQL数据库生成脚本
- 求一条多表统计
- sql server 2008 express
- 最快速的删除一个表中的10000条记录的语句
declare @s datetime
set @s = '2010-08-27'
select cast(convert(varchar(10),@s,112) as int)+2结果
20100829加2是为了看到效果。
@id int output
AS
BEGIN
set @id=
isnull(
(select max(id)+1 from RepairBill where datediff(dd,left(id,8),getdate())=0),
cast(convert(varchar(8),getdate(),112) as int)*100+1
)
END
long 对应bigint
CREATE PROCEDURE dbo.GetRepairBillID;1
--declare
@id int output
AS declare @curtime int
BEGIN
select @curtime = convert(int,CONVERT(varchar(6), GETDATE(), 12))
if exists(select * from RepairBill where ID > @curtime *100 and ID < (@curtime*100+99) )
select @id = max(ID) + 1 from RepairBill where ID > @curtime *100 and ID < (@curtime*100+99)
else
select @id = @curtime*100 + 1
END