Create
Function
	[dbo].[Fn_TaminPrescriptionOld_GetReceptionId]
(
		@NationalCode Varchar(15),
		@TrackingCode Varchar(50),
		@EPRSC_ID BigInt
)
Returns Bigint
As
Begin
	Return
(
Select
		Top 1
				s.[ReceptionId]
	From [dbo].[tbl_TaminPrescriptionOld] As s
	Left Join [dbo].[tbl_TaminHeadOld] As h On h.[Id] = s.[HeadId]
	Left Join [dbo].[tblReception] As r On r.[mNumber] = s.[ReceptionId] And r.[mDate] = [dbo].[Fn_GetPersianDateStr](Null,'/') And r.[mCanceled] = 0
	Where	h.[NationalCode] = @NationalCode
	And		h.[TrackingCode] = @TrackingCode
	And		s.[EPRSC_ID] = @EPRSC_ID
	And		r.[mNumber] Is Not Null
)
End