SQL stored procedure generation sequential encoding

Source: Internet
Author: User

Use [WJKC]
GO
/****** object:storedprocedure [dbo].    [Address_getcode1] Script date:2016/3/29 Tuesday 10:20:47 ******/
SET ANSI_NULLS on
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
--Author: <Author,,Name>
--Create Date: <create date,,>
--Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo]. [Address_getcode1]
--Add The parameters for the stored procedure here
@CODE nvarchar [email protected] nvarchar (+), @ISTY int, @DETAIL nvarchar (250)
As
BEGIN
--Remove the maximum code
SET @CODE =null
SELECT TOP 1 @CODE =code from SHDZ
ORDER by CODE DESC
--if not taken out.
IF @CODE is NULL
BEGIN
SET @CODE = ' 01 '
END
ELSE
BEGIN
DECLARE @NUM VARCHAR (2)
--Take out the number +1
SET @NUM =convert (VARCHAR, (CONVERT (Int,right (@CODE, 2)) +1))

SET @NUM =replicate (' 0 ', 2-len (@NUM)) [email protected]

SET @[email protected]
END
END

SQL stored procedure generation sequential encoding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.