Create Function
[dbo].[Fn_Reception_GetRow]
(
--Declare
		@mNumber Bigint = -1 --6328
)
Returns Table
As
Return
Select
		th.[TrackingCode] [TrackingCodeTamin],
		t.[PRESCDATE] [TaminDate],
		ssh.[TrackingCode] [TrackingCodeSalamt],
		dr.[mMedicalNo],
		-----------------------------------------
		i2.[mName] Insures2Name,
		i2.[mInsureDependency],
		i2.[mFranshiz4AzadTest],
		i2d.[mKDate],
		i2d.[mKProf],
		i2d.[mKTech],
		
		rrs.[InsuranceCode],
		rrs.[InsuranceName],
		-----------------------------------------
		s.[mNumber],
		s.[mPreShowNo],
		s.[mShowNo],
		s.[mDate],
		s.[mTime],
		s.[mRegDate],
		s.[mSentFromNo],
		s.[mInsureCode],
		s.[mInsure2Code],
		s.[mInsureSheetDate],
		s.[mInsureSheetNo],
		s.[mFName],
		s.[mLName],
		s.[mGender],
		s.[mAge],
		s.[mAgeUnit],
		s.[mDoctorNo],
		s.[mResponseDate],
		s.[mResponseDateDiff],
		s.[mTel],
		s.[mPrescriptionDate],
		s.[mClinicalData],
		s.[mTotalPrice],
		s.[mFranshiz],
		s.[mInsurePortion],
		s.[mSickPortion],
		s.[mInsure2Portion],
		s.[mDiscount],
		s.[mSickPayment],
		s.[mRest],
		s.[mRestEquiDate],
		s.[mCanceled],
		s.[mCancelDate],
		s.[mPayedMoney],
		s.[mPayablePrice],
		s.[mShowPayable],
		s.[mShowRest],
		s.[temp1],
		s.[temp2],
		s.[temp3],
		s.[temp4],
		s.[temp5],
		s.[temp6],
		s.[mPriceDate],
		s.[musername],
		s.[mHaveSample],
		s.[mNoPrint],
		s.[mInsureSheetPageNo],
		s.[mExtraMoney],
		s.[mName],
		s.[mCompAge],
		s.[mLabMoney],
		s.[mLackSamplse],
		s.[mGreenpAns],
		s.[mYellowAns],
		s.[mSumInsure],
		s.[mPrintedAns],
		s.[mRegUser],
		s.[mPrintUser],
		s.[mPreName],
		s.[mFaRespPrintdate],
		s.[mRespUser],
		s.[mFather],
		s.[mAddress],
		s.[mPatCode],
		s.[mCytCode],
		s.[mRegEditUser],
		s.[mCantPrintResp],
		s.[mSampler],
		s.[mRespCom],
		s.[mNoPrintPath],
		s.[mNoPrintCyth],
		s.[mEmergency],
		s.[mMobile],
		s.[mGreenTest],
		s.[mYellowTest],
		s.[mFileID],
		s.[mPrnLabelNo],
		s.[mRespPrintTime],
		s.[mRegSMS],
		s.[mRespSMS],
		s.[mNoRegPrint],
		s.[mEmail],
		s.[mESigned],
		s.[mPregnant],
		s.[mMelliCode],
		s.[mVerified],
		s.[mRecType],
		s.[mLinkID],
		s.[mOfficeNo],
		s.[mLetterNo],
		s.[mLetterDate],
		s.[mIs4Addiction],
		s.[mCreditCard_Used],
		s.[mCreditCard_BankID],
		s.[mCreditCard_Price],
		s.[mCreditCard_Trans_ID],
		s.[mBirthDate],
		s.[mIs4QC],
		s.[mLiquidated],
		s.[mRemote_Answer],
		s.[mRemote_Answer_Accepted],
		s.[mRemote_Answer_Checked],
		s.[mRemote_Answer_Comment],
		s.[mRemote_Answer_User],
		s.[mIsSampled],
		s.[mRemote_Answer_Alert],
		s.[mRemote_Answer_DateTime],
		s.[mSamplingDateTime],
		s.[mOnlineRecNo],
		s.[mPhoto],
		s.[mDate4Insure],
		s.[mIntroducerID],
		s.[mRegTLG],
		s.[mRespTLG],
		s.[mMegaLabID],
		s.[mMegaLabComment],
		s.[mHISLinkID],
		s.[mResponseDelivered],
		s.[mRespMedia],
		s.[mGUID],
		s.[samadcode],
		s.[mTotalPriceKhadamat],
		s.[mFranshizKhadamat],
		s.[mInsurePortionKhadamat],
		s.[mInsure2KDateID],
		s.[mInsure2Franshiz],
		s.[mHistoryByMelli],
		s.[mInsurePriceDate],
		s.[mDiscountKhadamt],
		s.[mSpecialkhadamat],
		s.[mCanceledReason],
		s.[mViewRespOnline],
		s.[DitasEducationLevel],
		s.[DitasMaritalStatus],
		s.[DitasCountriesIso],
		s.[DitasAdmissionType],
		s.[DitasReasonForEncounter],
		s.[DitasFlagId],
		s.[mOnlineRecNoTakmili]
		


	From [dbo].[tblreception] As s
	Left Join [dbo].[tblDoctors] As dr On dr.[mID] = s.[mDoctorNo]
	------------------ تامین اجتماعی -----------------------------------------------
	Left Join [dbo].[tbl_TaminPrescriptionOld] As t On t.[ReceptionId] = s.[mNumber]
	Left Join [dbo].[tbl_TaminHeadOld] As th On th.[Id] = t.[HeadId]
	------------------ بیمه سلامت -----------------------------------------------
	Left Join [dbo].[tbl_SalamatPrescription] As ss On ss.[ReceptionId] = s.[mNumber]
	Left Join [dbo].[tbl_SalamatHead] As ssh On ssh.[Id] = ss.[HeadId]
	------------------ بیمه تکمیلی ---------------------------------------------
	Left Join [dbo].[tblInsures2] As i2 On i2.[mID] = s.[mInsure2Code]
	Left Join [dbo].[tblInsure2KDate] As i2d On i2d.[mInsure2ID] = i2.[mID] And i2d.[mID] = s.[mInsure2KDateID]
	Left Join [dbo].[Rasa_InsuranceLists] As rrs On rrs.[Id] = i2.[RasaId]
	Where s.[mNumber] =  @mNumber
