Genrate Number 0001 - 0002- 0010 - 0100- --- 9999 [英] Genrate Number 0001 - 0002- 0010 - 0100- --- 9999

查看:117
本文介绍了Genrate Number 0001 - 0002- 0010 - 0100- --- 9999的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

USE [RealEstate]
GO
/****** Object: StoredProcedure [dbo].[SP_AutoNumber] Script Date: 17/04/2014 12:00:31 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 

 
ALTER PROCEDURE [dbo].[SP_AutoNumber]
@code int,
@MaxValue int,
@LastValue int ,
@strGUID uniqueidentifier
 
AS
 
(select @MaxValue = max(RealEstateNumber) from RlRegistrationRealEstate) 
 
if @MaxValue is null set @MaxValue = '0001' set @LastValue = right(@MaxValue,3) + 1 return right('000' + convert(varchar(4),@lastValue),4) set @MaxValue= @MaxValue + @LastValue
 

UPDATE [dbo].RlRegistrationRealEstate SET RealEstateNumber=@MaxValue WHERE GUID = @strGUID

推荐答案

看起来你对何时使用整数值感到困惑和varchar值。



整数将包含数字。数字的正常显示不包括前导零。设置@MaxValue ='0001'将为@MaxValue赋值1.前导零与整数无关。



如果要显示带前导零的整数,然后它需要在某处转换为字符串。通常,这将在UI演示文稿(即网页)而不是数据库中完成。



如果您希望存储带有前导零的数据数据库,那么数据类型需要是varchar而不是整数。
It looks like you are confused about when to use integer values and varchar values.

An integer will contain the number. The normal presentation of the number doesn't include leading zeros. Setting @MaxValue = '0001' will give @MaxValue the value of 1. The leading zeros are irrelevant for integers.

If you wish to display an integer with leading zeros, then it needs to be converted to a string somewhere. Normally, this would be done in the UI presentation (ie the web page) rather than the database.

If you wish to store the data with the leading zeros in the database, then the datatypes need to be varchar rather than integer.


这篇关于Genrate Number 0001 - 0002- 0010 - 0100- --- 9999的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆