日期:2014-05-17 浏览次数:20410 次
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-10-25 10:57:56
-- Version:
-- Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64)
-- Dec 28 2012 20:23:12
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: )
--
----------------------------------------------------------------
--> 测试数据:[comProduct]
if object_id('[comProduct]') is not null drop table [comProduct]
go
create table [comProduct]([ProdId] varchar(7))
insert [comProduct]
select '0021001' union all
select '0021002' union all
select '0021004'
--------------开始查询--------------------------
select RIGHT('00000'+CONVERT(VARCHAR(10),MAX(CONVERT(INT,[ProdId]))+1),7)
from [comProduct]
----------------结果----------------------------
/*
--------------
0021005
*/
create table comProduct (ProdId nvarchar(10))
insert into comProduct values('0021001')
insert into comProduct values('0021002')
insert into comProduct values('0021004')
select RIGHT(CAST(POWER(10,7) AS VARCHAR)+MAX(CONVERT(INT,ProdId))+1,7)from comProduct
/*
ProdId
0021005
*/
create table comProduct (ProdId nvarchar(10))
insert into comProduct values('0021001')
insert into comProduct values('0021002')
insert into comProduct values('0021004')
SELECT RIGHT('0000000'+LTRIM(CAST(MAX(prodid) AS BIGINT)+1),7) FROM comProduct
/*
0021005
*/
--> 测试数据:[comProduct]
if object_id('[comProduct]') is not null drop table [comProduct]
go
create tabl