sql 흐름 번호 생 성

1570 단어 SQL
--  :                  ,              。
--  :       :1.yymmdd+6    ( 20071113000001)--2.       ,         000001  。
      :
 --  
create  function   [dbo].[f_getid]()   
 returns   varchar(14)   
  as   
  begin   
  declare   @id   varchar(14),
            @dt   varchar(8),
            @maxdt varchar(8) 
  select   @dt=convert(varchar(8), getdate(),112)
  select   @maxdt=left(isnull(max(id),convert(varchar(8), getdate(),112)),8)  from bookid
  if @maxdt=@dt 
  begin 
  select   @id=@dt+right(1000001+isnull(right(max(id),6),0),6) 
  from   bookid   where   id   like   @dt+'%' 
  end  
  if @maxdt<>@dt
  begin
  select @id=@dt+'000001'
  end 
  return(@id)   
  end 
--  
CREATE TABLE [dbo].[bookid](
 [id] [varchar](14) COLLATE Chinese_PRC_BIN NOT NULL CONSTRAINT [DF_bookid_id]  DEFAULT ([dbo].[f_getid]()),
 [ISBN] [nchar](30) COLLATE Chinese_PRC_BIN NOT NULL,
 [inlibrary] [bit] NOT NULL CONSTRAINT [DF_bookid_inlibrary]  DEFAULT ((1)),
 CONSTRAINT [PK_bookid] PRIMARY KEY CLUSTERED 
(
 [id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

 
public static String getOrderNo(){
        long No = 0;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String nowdate = sdf.format(new Date());
        No = Long.parseLong(nowdate)*1000;//                   
        No+=getNo();
        return getUserId+No;
    }
    public static int getNo(){//        +1
        return 001;
    }

public static String getUserId(){
    return "123";
}

좋은 웹페이지 즐겨찾기