Click here to Skip to main content
16,005,377 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
 USE [Laboratory]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[pr_Patient_Insert]
	@iErrorCode int OUTPUT,
	@LASID int OUTPUT,
	@PatientName varchar(50),
	@Age int,
	@AgeUnit char(1),
	@Sex char(1),
	@DOB datetime,
	@Priorty char(1),
	@EnterBy int,	
	@Shift char(1),	
	@PatientType char(1),
	@Relation varchar(4),
	@RelativeName varchar(30),
	@PH# varchar(15),
	@Email varchar(50),
	@ReferBy varchar(30),
	@PUID int=null,
	@PenalID int,
	@CashReceiptNo int,
	@CashReceivedBY varchar(30),
	@TotalAmount float,	
	@DiscountPtage int,
	@DiscountBy int
	AS
SET NOCOUNT ON
-----------
declare @seed int, @newSeede int;
set @seed = IDENT_SEED('Patient');
set @newSeede = YEar(Getdate())%100*1000000;
if (@seed <> @newSeede)
	BEGIN
		DBCC CHECKIDENT ( Patient, RESEED,@newSeede )
	End
if( @PUID is null)
	BEGIN
		select @PUID= Max(LASID)+1 from Patient
	END
------------
INSERT INTO [dbo].[Patient] (
	[PatientName],
	[Age],
	[AgeUnit],
	[Sex],
	[DOB],
	[Priorty],
	[EnterBy],	
	[Shift],	
	[PatientType],
	[Relation],
	[RelativeName],
	[PH#],
	[Email],
	[ReferBy],
	[PUID],
	[PenalID],
	[CashReceiptNo],
	[CashReceivedBY],
	[TotalAmount],	
	[DiscountPtage],
	[DiscountBy])
	 VALUES (
	@PatientName,
	@Age,
	@AgeUnit,
	@Sex,
	@DOB,
	@Priorty,
	@EnterBy,	
	@Shift,	
	@PatientType,
	@Relation,
	@RelativeName,
	@PH#,
	@Email,
	@ReferBy,
	@PUID,
	@PenalID,
	@CashReceiptNo,
	@CashReceivedBY,
	@TotalAmount,	
	@DiscountPtage,
	@DiscountBy
)
SELECT @iErrorCode=@@ERROR
-- Get the IDENTITY value for the row just inserted.
SELECT @LASID=SCOPE_IDENTITY()
--endregion


this is my store procedure when i excute this procedure
the
SQL
DBCC CHECKIDENT ( Patient, RESEED,@newSeede )

part of code
XML
if (@seed <> @newSeede)
    BEGIN
        DBCC CHECKIDENT ( Patient, RESEED,@newSeede )
    End

excute every time and reseed the column either the condition of if statment is true or false
when i comments the line "DBCC CHECKIDENT ( Patient, RESEED,@newSeede)"
then it works properly
plz help me what i am doing wrong
thanks
My identity field in table is LASID and i want to autogenerate the value but want to start from 0 every year with year postfix means in 2011 it start from 11000000 and in 2012 it start frme 12000000 for 2013 start will be 13000000 ect how can i do this.
Posted
Updated 16-Jul-11 16:14pm
v3
Comments
Sergey Alexandrovich Kryukov 23-May-11 9:59am    
Not clear what's the trouble, help with what.
--SA
[no name] 31-May-11 4:40am    
Hi, please explain the challenge you are facing

1 solution

@seed is the highest value in the table
@newseede ia a value created just above it, based on a GetDate() value. The change that they are not equal must be pretty near 100%.

By the way you do:
YEar(Getdate())%100*1000000. Year(GetDate()) =>
Year(GetDate()) = 2011
2011 %100 = 11
11 * 1000000 = 11000000.

You might wanna do a print @seed, @newseede. If you run the SP you can see the value.

Better. What is the Identity Field in the table? Is it set as a Identity field with step 1. It then autogenerates the value for your field. Much easier.
 
Share this answer
 
Comments
sher ali 16-Jul-11 22:00pm    
thanks for reply digimanus identity field in table is LASID and i want to autogenerate the value but want to start from 0 every year with year postfix means in 2011 it start from 11000000 and in 2012 it start frme 12000000 for 2013 start will be 13000000 ect how can i do this.

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