Click here to Skip to main content
16,008,469 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted
Comments
[no name] 19-Apr-14 8:41am    
Posting and reposting the same bit of code over and over (this is the 5th time that I know of now) without bothering to ask a question or describe a problem is not going to get you anywhere. The only thing that it will get you is banned from the site for abusing the system.

Don't.
Store it as separate numbers and convert those to a string for presentation when you retrieve the information.
 
Share this answer
 
Comments
haythamsoft 19-Apr-14 14:23pm    
thanks i,m try my freind to change datatype to varchar(20) but not run correct stored correct if you can RE-write This Store to Store Number Like This 0001-0002-0003-0100 -1000-9999 THANKS
 
Share this answer
 
try this example...already i used this same requirement;

C#
ALTER PROCEDURE [dbo].[SP_AutoNumber]
@strGUID uniqueidentifier
AS
BEGIN
	
	SET NOCOUNT ON;
   
if exists(select * from TABLENAME where GUID = @strGUID)
begin
SELECT RIGHT(REPLICATE('0', 4) + CAST(CAST(COALESCE(MAX(columnname), 0) AS INT)  AS VARCHAR), 4) dcno
  FROM
(
  SELECT TOP 1 columnname[generatecolumn]
    FROM Tablename
   ORDER BY sno DESC
) q;
end
else



begin

SELECT RIGHT(REPLICATE('0', 4) + CAST(CAST(COALESCE(MAX(columnname), 0) AS INT) + 1 AS VARCHAR), 4) dcno
  FROM
(
  SELECT TOP 1 columnname[generatecolumn]
    FROM tablename
   ORDER BY sno DESC
) q;

end
END
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900