set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

create PROCEDURE [dbo].[STPGetLastCheckInDetailCode]
	@User int
AS
declare @LastDetailCode int
SELECT     @LastDetailCode=MAX(CheckInTBL.FK_DocSysCode)  
FROM         CheckInTBL INNER JOIN
                      VWDocumentDetail_DocHeader ON CheckInTBL.FK_DocSysCode = VWDocumentDetail_DocHeader.DetailCode INNER JOIN
                      DocTbl ON VWDocumentDetail_DocHeader.Fk_docSysCode = DocTbl.SysCode
WHERE     (DocTbl.UserIDNO = @user)
return @LastDetailCode