1. if object_id('up_getBaseNo') is not null
    2. begin
    3. drop procedure up_getBaseNo
    4. end
    5. go
    6. alter proc [dbo].[up_getBaseNo](
    7. @hid char(6)--酒店id
    8. , @as_baseName varchar(30)
    9. , @as_other varchar(30) = ''--取消号的其它信息,例如按日期取号的话,这里传日期的字符串,不能为null
    10. , @no47 tinyint = 0 --不含47
    11. , @len tinyint = 6 --返回长度,前面补零,但最大长度只支持8
    12. )
    13. as
    14. --set nocount on
    15. /*******************************************************************************************
    16. 名称:取流水号值
    17. 说明:取流水号值
    18. 作者:向以胜
    19. 日期:2021-02-05
    20. [up_getBaseNo] @hid = '000003',@as_baseName = 'res',@as_other = '2016-05-23',
    21. [up_getBaseNo] @hid = '000002',@as_baseName = 'hotel',@as_other = '2016-05-22',@len = 0,@no47 = 1
    22. select * from seed
    23. --取号种子表
    24. create table [dbo].[seed](
    25. [id] [uniqueidentifier] primary key not null,
    26. [hid] [char](6) not null,
    27. [name] [varchar](30) not null,
    28. [value] [int] null,
    29. [other] [varchar](30) null
    30. )
    31. ********************************************************************************************/
    32. declare @value varchar(10)
    33. set @as_other = ISNULL(@as_other,'')
    34. update seed set value = case when value < 100000001 or value > 199999999 then 100000001 else value + 1 end where hid = @hid and name = @as_baseName and other = @as_other
    35. --如果没有插入一条新记录
    36. if @@rowcount = 0
    37. begin
    38. insert into seed(id,hid,name,other,value)values(newid(),@hid,@as_baseName, @as_other ,100000001)
    39. --delete seed where hid = @hid and name = @as_baseName and isnull(other,'') <> @as_other
    40. end
    41. declare @value_ori varchar(10)
    42. select @value = value from seed where hid = @hid and name = @as_baseName and isnull(other,'') = @as_other
    43. set @value_ori = @value
    44. if @no47 = 1
    45. begin
    46. if RIGHT(@value,1) = '4' or RIGHT(@value,1) = '7' set @value = @value + 1
    47. if substring(@value,8,1) = '4' or substring(@value,8,1) = '7' set @value = @value + 10
    48. if substring(@value,7,1) = '4' or substring(@value,7,1) = '7' set @value = @value + 100
    49. if substring(@value,6,1) = '4' or substring(@value,6,1) = '7' set @value = @value + 1000
    50. if substring(@value,5,1) = '4' or substring(@value,5,1) = '7' set @value = @value + 10000
    51. if substring(@value,4,1) = '4' or substring(@value,4,1) = '7' set @value = @value + 100000
    52. if substring(@value,3,1) = '4' or substring(@value,3,1) = '7' set @value = @value + 1000000
    53. if substring(@value,2,1) = '4' or substring(@value,2,1) = '7' set @value = @value + 10000000
    54. if @value_ori <> @value
    55. begin
    56. update seed set value = @value where hid = @hid and name = @as_baseName and isnull(other,'') = @as_other
    57. end
    58. end
    59. --将other中的-去掉后拼接在前面一起返回。
    60. declare @return varchar(10)
    61. if @len = 0
    62. set @return = convert(varchar(10) , convert(int,RIGHT(@value,8) ))
    63. else
    64. set @return = right(@value,@len)
    65. select replace(@as_other,'-','') + @return as seqno
    66. return