in below qury remove /r/n and clean: drop table #UpperTable10…
- User
in below qury remove /r/n and clean: drop table #UpperTable10
===============================
// SalaryClasses.Resources.SC_129 private string query = "\r\nDeclare @YearMonth int = #YearMonth;\r\nDeclare @SerialPay int = #SerialPay;\r\nWITH temp as\r\n(\r\nselect InsBaseTypeCode,Prc,Oprc,Cprc, ROW_NUMBER() OVER(Partition by InsBaseDetailTypes.InsBaseTypeCode ORDER BY date desc) \r\nas rw from RuleSalaries as RuleSalaries\r\ninner join \r\nInsBaseDetailTypes as InsBaseDetailTypes on RuleSalaries.RuleSalaryTitleCode=InsBaseDetailTypes.RuleSalaryTitleCode\r\nwhere RuleSalaries.RuleSalaryTitleCode in (120,121,122,123,126)\r\n)\r\n\t\r\nSELECT\r\nYearMonth = YearMonth,\r\nMastPaysView_RegionCode=MastPaysView_RegionCode,\r\n\tMastPaysView_EmpYear=Convert(nvarchar(8), (RIGHT(CONVERT(nvarchar(max),EYear+100),2)+'/'+RIGHT(CONVERT(nvarchar(max),EMonth+100),2)+'/'+'00')),\r\n\tEmpBaseDate=CASE WHEN LEN(EmpBaseDate)=8 THEN SUBSTRING(CONVERT(NVARCHAR(20), EmpBaseDate), 1, 4)\r\n\t+'/'\r\n\t+ SUBSTRING(CONVERT(NVARCHAR(20), EmpBaseDate), 5, 2) \r\n\t+'/'\r\n\t+ SUBSTRING(CONVERT(NVARCHAR(20), EmpBaseDate), 7, 2) else EmpBaseDate end,\r\n DeductOver30=DeductOver30,\r\n SumDeductIncludeSanavatGhabl=0,\r\n MzoodhengamkosooratbazneshastegiEmpBaz=MzoodhengamkosooratbazneshastegiEmpBaz,\r\n AghsaatEnteghalHaghbime=AghsaatEnteghalHaghbime,\r\n EmpBazSanavatGhbal=0,\r\n OrgBazSanavatghabl=0,\r\n\tEmptype2 = Emptype2,\r\n\tJozBBand11=JozBBand11,\r\n\tTafavotTatbigh2=0,\r\n\tTafavotTatbigh3=0,\r\n MostakhdemID=MostakhdemID,\r\n SandoghChangeDate=SandoghChangeDate,\r\n\tSanavatGhairRasmi=' ',\r\n\tMastPaysView_InsDateUp30=MastPaysView_InsDateUp30,\r\n Hokm = Hokm,\r\n Marriage = Marriage,\r\n Reshteh = Reshteh,\r\n Madrak = Madrak,\r\n Major = Major,\r\n Gender = Gender,\r\n\tEmptype = Emptype,\r\n SazPost = SazPost,\r\n IsarStatus = IsarStatus,\r\n IsarRelStatus = IsarRelStatus,\r\n Rasteh = Rasteh,\r\n Date = Date,\r\n Employees_Name = Employees_Name,\r\n Employees_LastName = Employees_LastName,\r\n Employees_Gender = Employees_Gender,\r\n Employees_FatherName = Employees_FatherName,\r\n Employees_NationalCode = Employees_NationalCode,\r\n Employees_IdNo = Employees_IdNo,\r\n Employees_IssuePlace = Employees_IssuePlace,\r\n Employees_Birthplace = Employees_Birthplace,\r\n BirthDate =CASE WHEN LEN(BirthDate)=8 THEN SUBSTRING(CONVERT(NVARCHAR(20), BirthDate), 1, 4)\r\n\t+'/'\r\n\t+ SUBSTRING(CONVERT(NVARCHAR(20), BirthDate), 5, 2) \r\n\t+'/'\r\n\t+ SUBSTRING(CONVERT(NVARCHAR(20), BirthDate), 7, 2) else BirthDate end,\r\n MastPaysView_EmpID = MastPaysView_EmpID,\r\n MastPaysView_EduCode = MastPaysView_EduCode,\r\n MastPaysView_EduSubCode = MastPaysView_EduSubCode,\r\n Military = Military,\r\n MastPaysView_Rasteh = MastPaysView_Rasteh,\r\n MastPaysView_Sazpost = MastPaysView_Sazpost,\r\n MastPaysView_Rshteh = MastPaysView_Rshteh,\r\n Rotbeh = Rotbeh,\r\n MastPaysView_Tbgh = MastPaysView_Tbgh,\r\n MastPaysView_ChildNo = MastPaysView_ChildNo,\r\n ServiceType = ServiceType,\r\n EmptypePosition = EmptypePosition,\r\n MastPaysView_IsarCode = MastPaysView_IsarCode,\r\n\tMastPaysView_IsarRelationCode=MastPaysView_IsarRelationCode,\r\n MastPaysView_EmpDate2 = MastPaysView_EmpDate2,\r\n MastPaysView_ChgDate = MastPaysView_ChgDate,\r\n HokmDate = HokmDate,\r\n MadrakEmp = MadrakEmp,\r\n MastPaysView_Salcnd = MastPaysView_Salcnd,\r\n\tPhoneNum=PhoneNum,\r\n Pay1 = Pay1,\r\n Pay2 = Pay2,\r\n Pay3 = Pay3,\r\n Pay4 = Pay4,\r\n Pay5 = Pay5,\r\n Pay6 = Pay6,\r\n Pay7 = Pay7,\r\n Pay8 = Pay8,\r\n Pay9 = Pay9,\r\n Pay10 = Pay10,\r\n Pay11 = Pay11,\r\n Pay12 = Pay12,\r\n Sayer = Sayer,\r\n Pay13 = Pay13,\r\n\tSayerEmp307=SayerEmp307,\r\n\tSayerEmp309=SayerEmp309,\r\n\tSayerEmp310=SayerEmp310,\r\n SayerEmp313=SayerEmp313,\r\n\tPay51 = Pay51,\r\n Pay18Rotbehbandi=Pay18Rotbehbandi,\r\n Pay19Tarmim=Pay19Tarmim,\r\n PayNegahdasht=0,\r\n\tPay46 = Pay46,\r\n Pay14 = Pay14,\r\n SumPay = SumPay,\r\n Emp_Baz = Emp_Baz,\r\n Org_Baz = Org_Baz,\r\n MSumPay = MSumPay,\r\n MEmpBaz = MEmpBaz,\r\n MOrgBaz = MOrgBaz,\r\n Code95 = Code95,\r\n\tCode97 = Code97,\r\n Code96 = Code96,\r\n Code27 = Code27,\r\n Mogarrari = Mogarrari,\r\n SayerOrg = SayerOrg,\r\n SayerEmp =SayerEmp,\r\n SumKasrBaz = Mogarrari+Emp_Baz+Org_Baz+SayerOrg+SayerEmp+MEmpBaz+MOrgBaz-SayerEmp307+SayerEmp309+SayerEmp310+SayerEmp313,\r\n\tTrialDate = TrialDate,\r\n\tMastPaysView_InsTypeCode=MastPaysView_InsTypeCode\r\n\t\tINTO #UpperTable10\r\n\tFROM (\r\nSELECT\r\nYearMonth = YearMonth,\r\nMastPaysView_RegionCode=MastPaysView_RegionCode,\r\n\tMastPaysView_EmpYear_Month= CASE WHEN (SELECT CHARINDEX('-',MastPaysView_EmpYear_Month ) AS a)- (SELECT CHARINDEX('\',MastPaysView_EmpYear_Month ) AS a) =2 THEN REPLACE(MastPaysView_EmpYear_Month, '\', '0')\r\n\t\t\t\t\t\t\t\t\t WHEN (SELECT CHARINDEX('-',MastPaysView_EmpYear_Month ) AS a)- (SELECT CHARINDEX('\',MastPaysView_EmpYear_Month ) AS a) =3 THEN REPLACE(MastPaysView_EmpYear_Month, '\', '')ELSE '00000' END,\r\n\tEmpBaseDate=CASE WHEN LEN(EmpBaseDate)=8 THEN REPLACE(EmpBaseDate,'/','')+'01' ELSE EmpBaseDate END\t,\r\n DeductOver30=DeductOver30,\r\n SumDeductIncludeSanavatGhabl=0,\r\n MzoodhengamkosooratbazneshastegiEmpBaz=MzoodhengamkosooratbazneshastegiEmpBaz,\r\n AghsaatEnteghalHaghbime=AghsaatEnteghalHaghbime,\r\n EmpBazSanavatGhbal=0,\r\n OrgBazSanavatghabl=0,\r\n\tJozBBand11=JozBBand11,\r\n\tTafavotTatbigh2=0,\r\n\tTafavotTatbigh3=0,\r\n MostakhdemID=MostakhdemID,\r\n SandoghChangeDate=SandoghChangeDate,\r\n\tSanavatGhairRasmi=' ',\r\n\tMastPaysView_InsDateUp30=MastPaysView_InsDateUp30,\r\n Hokm = Hokm,\r\n\tEmptype2 = Emptype2,\r\n Marriage = Marriage,\r\n Reshteh = Reshteh,\r\n Madrak = Madrak,\r\n Major = Major,\r\n Gender = Gender,\r\n\tEmptype = Emptype,\r\n SazPost = SazPost,\r\n IsarStatus = IsarStatus,\r\n IsarRelStatus = IsarRelStatus,\r\n Rasteh = Rasteh,\r\n Date = Date,\r\n Employees_Name = Employees_Name,\r\n Employees_LastName = Employees_LastName,\r\n Employees_Gender = Employees_Gender,\r\n Employees_FatherName = Employees_FatherName,\r\n Employees_NationalCode = Employees_NationalCode,\r\n Employees_IdNo = Employees_IdNo,\r\n Employees_IssuePlace = Employees_IssuePlace,\r\n Employees_Birthplace = Employees_Birthplace,\r\n BirthDate =CASE WHEN LEN(BirthDate)=8 THEN REPLACE(BirthDate,'/','')+'01' ELSE BirthDate END\t,\r\n MastPaysView_EmpID = MastPaysView_EmpID,\r\n MastPaysView_EduCode = MastPaysView_EduCode,\r\n MastPaysView_EduSubCode = MastPaysView_EduSubCode,\r\n Military = Military,\r\n MastPaysView_Rasteh = MastPaysView_Rasteh,\r\n MastPaysView_Sazpost = MastPaysView_Sazpost,\r\n MastPaysView_Rshteh = MastPaysView_Rshteh,\r\n Rotbeh = Rotbeh,\r\n MastPaysView_Tbgh = MastPaysView_Tbgh,\r\n MastPaysView_ChildNo = MastPaysView_ChildNo,\r\n ServiceType = ServiceType,\r\n EmptypePosition = EmptypePosition,\r\n MastPaysView_IsarCode = MastPaysView_IsarCode,\r\n\tMastPaysView_IsarRelationCode=MastPaysView_IsarRelationCode,\r\n MastPaysView_EmpDate2 = MastPaysView_EmpDate2,\r\n MastPaysView_ChgDate = MastPaysView_ChgDate,\r\n HokmDate = HokmDate,\r\n MadrakEmp = MadrakEmp,\r\n MastPaysView_Salcnd = MastPaysView_Salcnd,\r\n\tPhoneNum=PhoneNum,\r\n Pay1 = Pay1,\r\n Pay2 = Pay2,\r\n Pay3 = Pay3,\r\n Pay4 = Pay4,\r\n Pay5 = Pay5,\r\n Pay6 = Pay6,\r\n Pay7 = Pay7,\r\n Pay8 = Pay8,\r\n Pay9 = Pay9,\r\n Pay10 = Pay10,\r\n Pay11 = Pay11,\r\n Pay12 = Pay12,\r\n Sayer = Sayer,\r\n Pay13 = Pay13,\r\n\tPay51 = Pay51,\r\n\tSayerEmp307=SayerEmp307,\r\n\tSayerEmp309=SayerEmp309,\r\n\tSayerEmp310=SayerEmp310,\r\n SayerEmp313=SayerEmp313,\r\n\tPay18Rotbehbandi=Pay18Rotbehbandi,\r\n Pay19Tarmim=Pay19Tarmim,\r\n\tPay46 = Pay46,\r\n Pay14 = Pay14,\r\n SumPay = SumPay,\r\n Emp_Baz = Emp_Baz,\r\n Org_Baz = Org_Baz,\r\n MSumPay = MSumPay,\r\n MEmpBaz = MEmpBaz,\r\n MOrgBaz = MOrgBaz,\r\n Code95 = Code95,\r\n\tCode97 = Code97,\r\n Code96 = Code96,\r\n Code27 = Code27,\r\n Mogarrari = Mogarrari,\r\n SayerOrg = SayerOrg,\r\n SayerEmp =SayerEmp,\r\n SumKasrBaz = SumKasrBaz,\r\n\tEYear=EYear,\r\n\tEMonth=EMonth,\r\n\tMastPaysView_InsTypeCode=MastPaysView_InsTypeCode,\r\n\tTrialDate = TrialDate\r\n\r\n\tFROM\r\n\t\t(\r\nSELECT\r\nYearMonth = YearMonth,\r\nMastPaysView_RegionCode=MastPaysView_RegionCode,\r\n\tMastPaysView_EmpYear_Month=CASE WHEN (SELECT CHARINDEX('\',MastPaysView_EmpYear ) AS a)=4 AND (SELECT CHARINDEX('/',MastPaysView_EmpYear ) AS a)=2 THEN REPLACE(MastPaysView_EmpYear, '/', '0') \r\n\t\t\t\t\t\t\t\t\tWHEN (SELECT CHARINDEX('\',MastPaysView_EmpYear ) AS a)=5 AND (SELECT CHARINDEX('/',MastPaysView_EmpYear ) AS a)=3 THEN REPLACE(MastPaysView_EmpYear, '/', '0') \r\n\t\t\t\t\t\t\t\t\tWHEN (SELECT CHARINDEX('\',MastPaysView_EmpYear ) AS a)=6 AND (SELECT CHARINDEX('/',MastPaysView_EmpYear ) AS a)=3 THEN REPLACE(MastPaysView_EmpYear, '/', '') \r\n\t\t\t\t\t\t\t\t\tWHEN (SELECT CHARINDEX('\',MastPaysView_EmpYear ) AS a)=5 AND (SELECT CHARINDEX('/',MastPaysView_EmpYear ) AS a)=2 THEN REPLACE(MastPaysView_EmpYear, '/', '') ELSE'checkshavad' END,\r\n DeductOver30=DeductOver30,\r\n\tMastPaysView_InsTypeCode=MastPaysView_InsTypeCode,\r\n SumDeductIncludeSanavatGhabl=0,\r\n MzoodhengamkosooratbazneshastegiEmpBaz=MzoodhengamkosooratbazneshastegiEmpBaz,\r\n AghsaatEnteghalHaghbime=AghsaatEnteghalHaghbime,\r\n EmpBazSanavatGhbal=0,\r\n OrgBazSanavatghabl=0,\r\n\tJozBBand11=JozBBand11,\r\n\tTafavotTatbigh2=0,\r\n\tTafavotTatbigh3=0,\r\n\tEmptype2 = Emptype2,\r\n MostakhdemID=CASE WHEN MostakhdemID<=1000000 OR (SUBSTRING(CONVERT(NVARCHAR(20), MostakhdemID),1,1) = SUBSTRING(CONVERT(NVARCHAR(20), MostakhdemID),6,1) AND SUBSTRING(CONVERT(NVARCHAR(20), MostakhdemID),1,1) = SUBSTRING(CONVERT(NVARCHAR(20), MostakhdemID),3,1) AND \r\n\t\t\t\t\t\t SUBSTRING(CONVERT(NVARCHAR(20), MostakhdemID),1,1) = SUBSTRING(CONVERT(NVARCHAR(20), MostakhdemID),4,1) AND SUBSTRING(CONVERT(NVARCHAR(20), MostakhdemID),1,1) = SUBSTRING(CONVERT(NVARCHAR(20), MostakhdemID),5,1))\r\n\t\t\t\t\t\t OR MostakhdemID=9999999999 OR MostakhdemID=999999999 OR MostakhdemID=99999999 OR MostakhdemID=9999999 \r\n\t\t\t\t\t\t OR MostakhdemID=8888888888 OR MostakhdemID=888888888 OR MostakhdemID=88888888 OR MostakhdemID=8888888 \r\n\t\t\t\t\t\t OR MostakhdemID=7777777777 OR MostakhdemID=777777777 OR MostakhdemID=77777777 OR MostakhdemID=7777777 \r\n\t\t\t\t\t\t OR MostakhdemID=6666666666 OR MostakhdemID=666666666 OR MostakhdemID=66666666 OR MostakhdemID=6666666 \r\n\t\t\t\t\t\t OR MostakhdemID=5555555555 OR MostakhdemID=555555555 OR MostakhdemID=55555555 OR MostakhdemID=5555555 \r\n\t\t\t\t\t\t OR MostakhdemID=4444444444 OR MostakhdemID=444444444 OR MostakhdemID=44444444 OR MostakhdemID=4444444 \r\n\t\t\t\t\t\t OR MostakhdemID=3333333333 OR MostakhdemID=333333333 OR MostakhdemID=33333333 OR MostakhdemID=3333333 \r\n\t\t\t\t\t\t OR MostakhdemID=2222222222 OR MostakhdemID=222222222 OR MostakhdemID=22222222 OR MostakhdemID=2222222 \r\n\t\t\t\t\t\t OR MostakhdemID=1111111111 OR MostakhdemID=111111111 OR MostakhdemID=11111111 OR MostakhdemID=1111111 \r\n\t\t\t\t\t\t OR MostakhdemID=123456789 OR MostakhdemID=12345678 OR MostakhdemID=1234567 \r\n\t\t\t\t\t\t THEN\tEmployees_NationalCode ELSE MostakhdemID END,\r\n SandoghChangeDate=SandoghChangeDate,\r\n\tSanavatGhairRasmi=' ',\r\n\tMastPaysView_InsDateUp30=MastPaysView_InsDateUp30,\r\n Hokm = Hokm,\r\n Marriage = Marriage,\r\n Reshteh = Reshteh,\r\n Madrak = Madrak,\r\n Major = Major,\r\n Gender = Gender,\r\n\tEmptype = Emptype,\r\n SazPost = SazPost,\r\n IsarStatus = IsarStatus,\r\n IsarRelStatus = IsarRelStatus,\r\n Rasteh = Rasteh,\r\n Date = Date,\r\n Employees_Name = Employees_Name,\r\n Employees_LastName = Employees_LastName,\r\n Employees_Gender = Employees_Gender,\r\n Employees_FatherName = Employees_FatherName,\r\n Employees_NationalCode = Employees_NationalCode,\r\n Employees_IdNo = Employees_IdNo,\r\n Employees_IssuePlace = Employees_IssuePlace,\r\n Employees_Birthplace = Employees_Birthplace,\r\n BirthDate =CASE WHEN SUBSTRING(BirthDate,1,2)='13' AND SUBSTRING(BirthDate,3,2)='13' THEN SUBSTRING(BirthDate,3,8) ELSE BirthDate END,\r\n MastPaysView_EmpID = MastPaysView_EmpID,\r\n MastPaysView_EduCode = MastPaysView_EduCode,\r\n MastPaysView_EduSubCode = MastPaysView_EduSubCode,\r\n Military = Military,\r\n MastPaysView_Rasteh = MastPaysView_Rasteh,\r\n MastPaysView_Sazpost = MastPaysView_Sazpost,\r\n MastPaysView_Rshteh = MastPaysView_Rshteh,\r\n Rotbeh = Rotbeh,\r\n MastPaysView_Tbgh = MastPaysView_Tbgh,\r\n MastPaysView_ChildNo = MastPaysView_ChildNo,\r\n ServiceType = ServiceType,\r\n EmptypePosition = EmptypePosition,\r\n EmpBaseDate =CASE WHEN SUBSTRING(EmpBaseDate,1,2)='13' AND SUBSTRING(EmpBaseDate,3,2)='13' THEN SUBSTRING(EmpBaseDate,3,8) ELSE EmpBaseDate END,\r\n MastPaysView_IsarCode = MastPaysView_IsarCode,\r\n\tMastPaysView_IsarRelationCode=MastPaysView_IsarRelationCode,\r\n MastPaysView_EmpDate2 = MastPaysView_EmpDate2,\r\n MastPaysView_ChgDate = MastPaysView_ChgDate,\r\n HokmDate = HokmDate,\r\n MadrakEmp = MadrakEmp,\r\n MastPaysView_Salcnd = MastPaysView_Salcnd,\r\n\tPhoneNum=PhoneNum,\r\n Pay1 = Pay1,\r\n Pay2 = Pay2,\r\n Pay3 = Pay3,\r\n Pay4 = Pay4,\r\n Pay5 = Pay5,\r\n Pay6 = Pay6,\r\n Pay7 = Pay7,\r\n Pay8 = Pay8,\r\n Pay9 = Pay9,\r\n Pay10 = Pay10,\r\n Pay11 = Pay11,\r\n Pay12 = Pay12,\r\n Sayer = Sayer,\r\n Pay13 = Pay13,\r\n\tPay51 = Pay51,\r\n\tPay18Rotbehbandi=Pay18Rotbehbandi,\r\n Pay19Tarmim=Pay19Tarmim,\r\n\tPay46 = Pay46,\r\n Pay14 = Pay14,\r\n SumPay = SumPay,\r\n Emp_Baz = Emp_Baz,\r\n Org_Baz = Org_Baz,\r\n MSumPay = MSumPay,\r\n MEmpBaz = CASE WHEN (Pay1>0) THEN round(((MSumPay)*tempPrc) /100,0)\r\n\t\t\t\t ELSE round(((MSumPay-Mogarrari)*tempPrc) /100,0)\r\n\t\t\t\t END ,\r\n MOrgBaz = CASE WHEN Pay1>0 THEN round(((MSumPay)*tempCPrc) /100,0)\r\n\t\t\t\t ELSE round(((MSumPay-Mogarrari)*tempCPrc) /100,0)\r\n\t\t\t\t end,\r\n Code95 = Code95,\r\n\tCode97 = Code97,\r\n Code96 = Code96,\r\n\tSayerEmp307=SayerEmp307,\r\n\tSayerEmp309=SayerEmp309,\r\n\tSayerEmp310=SayerEmp310,\r\n SayerEmp313=SayerEmp313,\r\n Code27 = Code27,\r\n Mogarrari = Mogarrari,\r\n SayerOrg = SayerOrg,\r\n SayerEmp =SayerEmp,\r\n SumKasrBaz = SumKasrBaz,\r\n\tEYear=EYear,\r\n\tEMonth=EMonth,\r\n\tTrialDate = TrialDate\r\n\tFrom\r\n\t\t(\r\nSELECT\r\nYearMonth = YearMonth,\r\n\tMastPaysView_RegionCode=MastPaysView_RegionCode,\r\n DeductOver30=(-1)(tempCPrc/100)),0)\r\n\t\t\t\t ELSE Org_Baz END, \r\n\tMSumPay=CASE WHEN ABS(MSumPay)<10 AND ABS(MSumPay)>0 THEN 0 ELSE MSumPay end ,\r\n MEmpBaz = MEmpBaz,\r\n MOrgBaz = MOrgBaz,\r\n Code95 = Code95,\r\n\tCode97 = Code97,\r\n Code96 = Code96,\r\n\tJozBBand11=JozBBand11,\r\n Code27 = Code27,\r\n Mogarrari = Mogarrari,\r\n SayerOrg = SayerOrg,\r\n SayerEmp = SayerEmp,\r\n\tSayerEmp307=SayerEmp307,\r\n\tSayerEmp309=SayerEmp309,\r\n\tSayerEmp310=SayerEmp310,\r\n SayerEmp313=SayerEmp313,\r\n\tSayerEmp308=SayerEmp308,\r\n\tSayerEmp328=SayerEmp328,\r\n SumKasrBaz = SumKasrBaz,\r\n\tEYear=EYear,\r\n\tEMonth=EMonth,\r\n\tTrialDate,\r\n tempPrc=tempPrc,\r\n\ttempCPrc=tempCPrc,\r\n\tSumPayWithOutMogharrari=SumPayWithOutMogharrari\r\n\tFrom\r\n\t\t(\r\nSELECT\r\nMastPaysView_RegionCode=MastPaysView_RegionCode,\r\n Hokm = Hokm,\r\n Marriage = Marriage,\r\n Reshteh = Reshteh,\r\n Madrak = Madrak,\r\n Major = Major,\r\n Gender = Gender,\r\n\tEmptype = Emptype,\r\n\tEmptype2=Emptype2,\r\n SazPost = SazPost,\r\n IsarStatus = IsarStatus,\r\n IsarRelStatus = IsarRelStatus,\r\n Rasteh = Rasteh,\r\n YearMonth = YearMonth,\r\n Date = Date,\r\n Employees_Name = Employees_Name,\r\n\tMostakhdemID=MostakhdemID,\r\n Employees_LastName = Employees_LastName,\r\n Employees_Gender = Employees_Gender,\r\n Employees_FatherName = Employees_FatherName,\r\n Employees_NationalCode = Employees_NationalCode,\r\n Employees_IdNo = Employees_IdNo,\r\n Employees_IssuePlace = Employees_IssuePlace,\r\n Employees_Birthplace = Employees_Birthplace,\r\n BirthDate = BirthDate,\r\n MastPaysView_EmpID = MastPaysView_EmpID,\r\n MastPaysView_EduCode = MastPaysView_EduCode,\r\n MastPaysView_EduSubCode = MastPaysView_EduSubCode,\r\n Military = Military,\r\n MastPaysView_Rasteh = MastPaysView_Rasteh,\r\n MastPaysView_Sazpost = MastPaysView_Sazpost,\r\n MastPaysView_Rshteh = MastPaysView_Rshteh,\r\n Rotbeh = Rotbeh,\r\n MastPaysView_Tbgh = MastPaysView_Tbgh,\r\n MastPaysView_ChildNo = MastPaysView_ChildNo,\r\n ServiceType = ServiceType,\r\n EmptypePosition = EmptypePosition,\r\n EmpBaseDate = EmpBaseDate,\r\n MastPaysView_IsarCode = MastPaysView_IsarCode,\r\n\tMastPaysView_IsarRelationCode=MastPaysView_IsarRelationCode,\r\n MastPaysView_EmpDate2 = MastPaysView_EmpDate2,\r\n MastPaysView_EmpYear = CONVERT(NVARCHAR(20), MastPaysView_EmpYear),\r\n MastPaysView_ChgDate = MastPaysView_ChgDate,\r\n ExemptDate = ExemptDate,\r\n HokmDate = HokmDate,\r\n MadrakEmp = MadrakEmp,\r\n IsarEmp = IsarEmp,\r\n MastPaysView_Salcnd = MastPaysView_Salcnd,\r\n Pay1 = Pay1,\r\n Pay2 = Pay2,\r\n Pay3 = Pay3,\r\n Pay4 = Pay4,\r\n Pay5 = Pay5,\r\n Pay6 = Pay6,\r\n Pay7 = Pay7,\r\n Pay8 = Pay8,\r\n Pay9 = Pay9,\r\n Pay10 = Pay10,\r\n Pay11 = Pay11,\r\n Pay12 = Pay12,\r\n Sayer = Sayer,\r\n Pay13 = Pay13,\r\n\tPay51 = Pay51,\r\n\tPay18Rotbehbandi=Pay18Rotbehbandi,\r\n Pay19Tarmim=Pay19Tarmim,\r\n\tPay46 = Pay46,\r\n Pay14 = Pay14,\r\n SumPay = SumPay,\r\n Emp_Baz = Emp_Baz,\r\n Org_Baz = Org_Baz,\r\n MSumPay = MSumPay,\r\n MEmpBaz = CASE WHEN SumPayWithOutMogharrari=0 AND (Emp_Baz<=0 OR Org_Baz<0) THEN round(((MSumPay-mogarrari)*tempPrc) /100,0)+Emp_Baz\r\n\t\t\t\t WHEN SumPayWithOutMogharrari=0 AND (Emp_Baz<0 OR Org_Baz<=0) THEN round(((MSumPay-mogarrari)*tempPrc) /100,0)+Emp_Baz\r\n\t\t\t\t ELSE round(((MSumPay)(cast (4 AS FLOAT)/cast (3 AS FLOAT)),0)\r\n ELSE MSumPay\r\n End,\r\n MEmpBaz =MEmpBaz,\r\n MOrgBaz = MOrgBaz,\r\n Code95 = Code95,\r\n\tCode97 = Code97,\r\n Code96 = Code96,\r\n\tJozBBand11=JozBBand11,\r\n Code27 = Code27,\r\n Mogarrari = Mogarrari,\r\n SayerOrg = SayerOrg,\r\n SayerEmp = SayerEmp,\r\n\tSayerEmp307=SayerEmp307,\r\n\tSayerEmp308=SayerEmp308,\r\n\tSayerEmp309=SayerEmp309,\r\n SayerEmp313=SayerEmp313,\r\n\tSayerEmp310=SayerEmp310,\r\n\tSayerEmp328=SayerEmp328,\r\n SumKasrBaz = SumKasrBaz,\r\n\tEYear=EYear,\r\n\tEMonth=EMonth,\r\n MastPaysView_Wrktim = MastPaysView_Wrktim,\r\n\tMastPaysView_InsTypeCode = MastPaysView_InsTypeCode,\r\n\tMastPaysView_InsDateUp30=MastPaysView_InsDateUp30,\r\n\tTrialDate,\r\n\ttempPrc=tempPrc,\r\n\ttempCPrc=tempCPrc,\r\n\tSumPayWithOutMogharrari=SumPayWithOutMogharrari\r\n\tFrom\r\n\t\t(\r\nSELECT\r\nMastPaysView_RegionCode=MastPaysView_RegionCode,\r\nHokm = Hokm,\r\n Marriage = Marriage,\r\n Reshteh = Reshteh,\r\n Madrak = Madrak,\r\n Major = Major,\r\n Gender = Gender,\r\n\tEmptype = Emptype,\r\n\tEmptype2=Emptype2,\r\n SazPost = SazPost,\r\n IsarStatus = IsarStatus,\r\n IsarRelStatus = IsarRelStatus,\r\n Rasteh = Rasteh,\r\n YearMonth = YearMonth,\r\n Date = Date,\r\n Employees_Name = Employees_Name,\r\n\tMostakhdemID=MostakhdemID,\r\n Employees_LastName = Employees_LastName,\r\n Employees_Gender = Gender,\r\n Employees_FatherName = Employees_FatherName,\r\n Employees_NationalCode = Employees_NationalCode,\r\n Employees_IdNo = Employees_IdNo,\r\n Employees_IssuePlace = Employees_IssuePlace,\r\n Employees_Birthplace = Employees_Birthplace,\r\n BirthDate = BirthDate,\r\n MastPaysView_EmpID = MastPaysView_EmpID,\r\n MastPaysView_EduCode = MastPaysView_EduCode,\r\n MastPaysView_EduSubCode = MastPaysView_EduSubCode,\r\n Military = Military,\r\n MastPaysView_Rasteh = MastPaysView_Rasteh,\r\n MastPaysView_Sazpost = MastPaysView_Sazpost,\r\n MastPaysView_Rshteh = MastPaysView_Rshteh,\r\n Rotbeh = Rotbeh,\r\n MastPaysView_Tbgh = MastPaysView_Tbgh,\r\n MastPaysView_ChildNo = MastPaysView_ChildNo,\r\n ServiceType = ServiceType,\r\n EmptypePosition = EmptypePosition,\r\n EmpBaseDate = EmpBaseDate,\r\n MastPaysView_IsarCode = MastPaysView_IsarCode,\r\n\tMastPaysView_IsarRelationCode=MastPaysView_IsarRelationCode,\r\n MastPaysView_EmpDate2 = MastPaysView_EmpDate2,\r\n MastPaysView_EmpYear = CASE WHEN (MastPaysView_Sazpost=14565 OR MastPaysView_Sazpost=13699 OR MastPaysView_Sazpost=13700 OR MastPaysView_Sazpost=13701 OR MastPaysView_Sazpost=5892 OR MastPaysView_Sazpost=147914 OR MastPaysView_Sazpost=10000844) AND EYear=0 THEN 1 else EYear+EMonth+'00' end,\r\n MastPaysView_ChgDate = MastPaysView_ChgDate,\r\n ExemptDate = ExemptDate,\r\n HokmDate = HokmDate,\r\n MadrakEmp = MadrakEmp,\r\n IsarEmp = IsarEmp,\r\n InsType = InsType,\r\n MastPaysView_Salcnd = MastPaysView_Salcnd,\r\n Pay1 = Pay1,\r\n Pay2 = Pay2,\r\n Pay3 = Pay3,\r\n Pay4 = Pay4,\r\n Pay5 = Pay5,\r\n Pay6 = Pay6,\r\n Pay7 = Pay7,\r\n Pay8 = Pay8,\r\n Pay9 = Pay9,\r\n Pay10 = Pay10,\r\n Pay11 = Pay11,\r\n Pay12 = Pay12,\r\n Sayer = Sayer,\r\n Pay13 = Pay13,\r\n\tPay51 = Pay51,\r\n\tPay18Rotbehbandi=Pay18Rotbehbandi,\r\n Pay19Tarmim=Pay19Tarmim,\r\n\tPay46 = Pay46,\r\n Pay14 = Pay14,\r\n SumPay = SumPay,\r\n Emp_Baz =Emp_Baz,\r\n Org_Baz =Org_Baz,\t\r\n MSumPay = CASE WHEN SumPayWithOutMogharrari=0 AND (Emp_Baz<=0 OR Org_Baz<0) THEN Pay800+PayBackValUnder100-SayerEmp\r\n\t\t\t\t WHEN SumPayWithOutMogharrari=0 AND (Emp_Baz<0 OR Org_Baz<=0) THEN Pay800+PayBackValUnder100-SayerEmp\r\n\t\t\t\t ELSE Pay800+PayBackValUnder100 END ,\r\n MEmpBaz = MEmpBaz,\r\n MOrgBaz = MOrgBaz,\r\n Code95 = Code95,\r\n\tCode97 = Code97,\r\n Code96 = Code96,\r\n\tJozBBand11=JozBBand11,\r\n Code27 = Code27,\r\n Mogarrari = Mogarrari,\r\n SayerOrg = SayerOrg,\r\n SayerEmp = SayerEmp,\r\n\tSayerEmp307=SayerEmp307,\r\n\tSayerEmp308=SayerEmp308,\r\n\tSayerEmp309=SayerEmp309,\r\n SayerEmp313=SayerEmp313,\r\n\tSayerEmp310=SayerEmp310,\r\n\tSayerEmp328=SayerEmp328,\r\n SumKasrBaz = SumKasrBaz,\r\n\tEYear=EYear,\r\n\tEMonth=EMonth,\r\n MastPaysView_Wrktim = MastPaysView_Wrktim,\r\n\t MastPaysView_InsTypeCode = MastPaysView_InsTypeCode,\r\n\t MastPaysView_InsDateUp30=MastPaysView_InsDateUp30,\r\n\tTrialDate,\r\n\ttempPrc=tempPrc,\r\n\ttempCPrc=tempCPrc,\r\n\tSumPayWithOutMogharrari=SumPayWithOutMogharrari\r\n\tFrom\r\n\t\t(\r\nSELECT\r\nMastPaysView_RegionCode=MastPaysView_RegionCode,\r\n Hokm = Hokm,\r\n Marriage = Marriage,\r\n Reshteh = N'دبيري',\r\n Madrak = Madrak,\r\n Major = Major,\r\n Gender = Gender,\r\n\tEmptype = Emptype,\r\n\tEmptype2=Emptype2,\r\n SazPost = SazPost,\r\n IsarStatus = IsarStatus,\r\n IsarRelStatus = IsarRelStatus,\r\n Rasteh = Rasteh,\r\n YearMonth = YearMonth,\r\n Date = Date,\r\n Employees_Name = Employees_Name,\r\n\tMostakhdemID=MostakhdemID,\r\n Employees_LastName = Employees_LastName,\r\n Employees_Gender = Employees_Gender,\r\n Employees_FatherName = Employees_FatherName,\r\n Employees_NationalCode = Employees_NationalCode,\r\n Employees_IdNo = Employees_IdNo,\r\n Employees_IssuePlace = Employees_IssuePlace,\r\n Employees_Birthplace = Employees_Birthplace,\r\n BirthDate = BirthDate,\r\n MastPaysView_EmpID = MastPaysView_EmpID,\r\n MastPaysView_EduCode = MastPaysView_EduCode,\r\n MastPaysView_EduSubCode = Major,\r\n Military = Military,\r\n MastPaysView_Rasteh = MastPaysView_Rasteh,\r\n MastPaysView_Sazpost = MastPaysView_Sazpost,\r\n MastPaysView_Rshteh = MastPaysView_Rshteh,\r\n Rotbeh = Rotbeh,\r\n MastPaysView_Tbgh = MastPaysView_Tbgh,\r\n MastPaysView_ChildNo = MastPaysView_ChildNo,\r\n ServiceType = ServiceType,\r\n EmptypePosition = EmptypePosition,\r\n EmpBaseDate = EmpBaseDate,\r\n MastPaysView_IsarCode = MastPaysView_IsarCode,\r\n\tMastPaysView_IsarRelationCode=MastPaysView_IsarRelationCode,\r\n MastPaysView_EmpDate2 = MastPaysView_EmpDate2,\r\n MastPaysView_EmpYear = MastPaysView_EmpYear,\r\n MastPaysView_ChgDate = MastPaysView_ChgDate,\r\n ExemptDate = ExemptDate,\r\n HokmDate = HokmDate,\r\n MadrakEmp = MadrakEmp,\r\n IsarEmp = IsarEmp,\r\n InsType = InsType, \r\n MastPaysView_Salcnd = MastPaysView_Salcnd,\r\n Pay1 = Pay1,\r\n Pay2 = Pay2,\r\n Pay3 = Pay3,\r\n Pay4 = Pay4,\r\n Pay5 = Pay5,\r\n Pay6 = Pay6,\r\n Pay7 = Pay7,\r\n Pay8 = Pay8,\r\n Pay9 = Pay9,\r\n Pay10 = Pay10,\r\n Pay11 = Pay11,\r\n Pay12 = Pay12,\r\n Sayer = Sayer,\r\n Pay13 = Pay13,\r\n\tPay51 = Pay51,\r\n\tPay18Rotbehbandi=Pay18Rotbehbandi,\r\n Pay19Tarmim=Pay19Tarmim,\r\n\tPay46 = Pay46,\r\n Pay14 = Pay14,\r\n SumPay = SumPay,\r\n Emp_Baz = CASE WHEN YearInsDateup30=@YearMonth AND DaysOfInsDateUp30>=1 THEN ROUND((ROUND(((SumPay)(DaysOfInsDateUp30),0)\r\n\tELSE ROUND(((SumPay)*tempPrc)/100,0) END,\r\n Org_Baz = Round(((SumPay)\r\n\tfrom(\r\n\tSELECT\r\n\tMastPaysView_RegionCode=MastPaysView_RegionCode,\r\n\tYearInsDateup30=CAST(SUBSTRING(CONVERT(NVARCHAR(20),MastPaysView_InsDateUp30),1,6) AS INT),\r\n DaysOfInsDateUp30=(CAST(SUBSTRING(CONVERT(NVARCHAR(20),MastPaysView_InsDateUp30),7,8) AS int)-1),\r\n\tHokm = IsNull((Select Description from SalaryHokmTypes where SalaryHokmTypeCode=OuterTable.MastPaysView_HokmTypeCode),' '),\r\n Marriage =case when MastPaysView_MarriageCode=5 and Payaaelemandi!=0 then N'متاهل' \r\n\t\t\t\t when MastPaysView_MarriageCode=5 and Payaaelemandi=0 then N'مجرد' \r\n when MastPaysView_MarriageCode=4 then N'معيل' else\r\n\t\t\t\tIsNull((Select Description from Marriages where MarriageCode=OuterTable.MastPaysView_MarriageCode),' ')end,\r\n Reshteh = IsNull((Select Description from JobBranchs where JobBranchCode=OuterTable.MastPaysView_Rshteh),' '),\r\n Madrak =case WHEN OuterTable.MadrakEmp=8 then N'سيکل' \r\n\t\t\t WHEN OuterTable.MadrakEmp=7 then N'ابتدايي' \r\n WHEN OuterTable.MadrakEmp IN(0,1) then N'بيسواد' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp=2 then N'خواندن ونوشتن' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp IN (3,4,5) THEN N'نهضت سوادآموزي' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp=7 then N'بيسواد' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp IN(18,19,20,21) then N'دكترا' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp=25 THEN N'معادل دكترا' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp=26 then N'دوره اول سطح' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp=27 then N'دوره دوم سطح' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp=28 then N'خارج' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp=29 then N'اجتهاد' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp=30 then N'درجه 1هنرمندي' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp=31 then N'درجه 2هنرمندي' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp=32 then N'درجه 3هنرمندي' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp=33 then N'درجه 4هنرمندي'\r\n\t\t\t\t WHEN OuterTable.MadrakEmp=34 then N'درجه 5هنرمندي' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp=35 then N'درجه 6هنرمندي' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp=36 then N'درجه 7هنرمندي' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp IN( 50,51,52,53,54,55) then N'ابتدايي' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp=56 then N'اول دبيرستان'\r\n\t\t\t\t WHEN OuterTable.MadrakEmp=57 then N'دوم دبيرستان' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp=58 then N'سوم دبيرستان' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp=59 then N'چهارم دبيرستان' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp=60 then N'پنجم دبيرستان' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp=61 then N'اول راهنمائي' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp=62 then N'دوم راهنمائي' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp=66 then N'اول دبيرستان'\r\n\t\t\t\t WHEN OuterTable.MadrakEmp=67 then N'دوم دبيرستان' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp=68 then N'سوم دبيرستان' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp IN(69,70) then N'دوره دوم تعليمات عمومي' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp=71 then N'اول دبيرستان' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp=72 then N'دوم دبيرستان' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp=73 then N'سوم دبيرستان'\r\n\t\t\t\t WHEN OuterTable.MadrakEmp=74 then N'دكترا' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp=75 then N'کارشناسي' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp=76 then N'کارشناسي ارشد' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp=77 then N'کارداني' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp=78 then N'تحصيلات قديم' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp=90 then N'ديپلم افتخاري' \r\n\t\t\t\t WHEN OuterTable.MadrakEmp=91 then N'فوق ديپلم'\r\n\tELSE IsNull((Select Description from Edus where EduCode=OuterTable.MadrakEmp),N'ليسانس') end ,\r\n Major = IsNull((Select Description from EduSubs where EduSubCode=OuterTable.MastPaysView_EduSubCode and OuterTable.MastPaysView_EduSubCode!=0 ),N'رياضي'),\r\n Gender = case OuterTable.Employees_Gender\r\n\twhen 0 then N'نامشخص'\r\n\twhen 1 then N'مرد'\r\n\twhen 2 then N'زن'\r\n\telse ' '\r\n\tend,\r\n Emptype = IsNull((Select Description from EmpTypes where EmpTypeCode=OuterTable.ServiceType),' '),\r\n\tEmptype2 = IsNull((Select EmpTypeCode from EmpTypes where EmpTypeCode=OuterTable.ServiceType),' '),\r\n SazPost = IsNull((Select Description from SazPosts where SazPostCode=OuterTable.MastPaysView_Sazpost),N'دبير'),\r\n IsarStatus = case when OuterTable.IsarEmp IN (3,9,21,22,23,24,25) then N' '\r\n\t\t\t\t\t when OuterTable.IsarEmp IN (1,5) then N'آزاده'\r\n\t\t\t\t\t when OuterTable.IsarEmp IN (2,10) then N'جانباز'\r\n\t\t\t\t\t when OuterTable.IsarEmp IN (4) then N'رزمنده'\r\n\t\t\t\t\t when OuterTable.IsarEmp IN (6) then N'مفقودالاثر'\r\n\t\t\t\t\t when OuterTable.IsarEmp IN (7,16,20) then N'جانباز - رزمنده - آزاده'\r\n\t\t\t\t\t when OuterTable.IsarEmp IN (8) then N'شهيد'\r\n\t\t\t\t\t when OuterTable.IsarEmp IN (11,14,18) then N'جانباز-آزاده'\r\n\t\t\t\t\t when OuterTable.IsarEmp IN (13,17) then N'جانباز - رزمنده'\r\n\t\t\t\t\t when OuterTable.IsarEmp IN (15,19) then N'رزمنده - آزاده'\r\n\r\n\tELSE \r\n\t\t\t IsNull((Select Description from Isars where IsarCode=OuterTable.IsarEmp),' ') end,\r\n IsarRelStatus =case when OuterTable.MastPaysView_IsarRelationCode IN (120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,141,142,143,144,145,146,162,164) then N' '\r\n\t\t\t\t\t when OuterTable.MastPaysView_IsarRelationCode IN (147,148,149,150,151,152,153,154,155,156,157,158,159,160,163) then N'فرزند جانباز'\r\n\t\t\t\t\t when OuterTable.MastPaysView_IsarRelationCode IN (135,136,137,140,165) then N'فرزند'\r\n\t\t\t\t\t when OuterTable.MastPaysView_IsarRelationCode IN (101,161) then N'فرزند شهيد'\r\n\t\t\t\t\t when OuterTable.MastPaysView_IsarRelationCode IN (107,108,109,110) then N'پدر شهيد'\r\n\t\t\t\t\t when OuterTable.MastPaysView_IsarRelationCode IN (117,118,119,102) then N'همسر شهيد'\r\n\t\t\t\t\t when OuterTable.MastPaysView_IsarRelationCode IN (103,104,105,106) then N'مادر شهيد'\r\n\t\t\t\t\t when OuterTable.MastPaysView_IsarRelationCode IN (115) then N'برادر شهيد'\r\n\t\t\t\t\t when OuterTable.MastPaysView_IsarRelationCode IN (116) then N'خواهر شهيد'\r\n\r\n\tELSE N' ' end,\r\n Rasteh = case OuterTable.MastPaysView_Rasteh\r\n\twhen 0 then N''\r\n\twhen 1 then N'آموزشي وفرهنگي'\r\n\twhen 2 then N'اداري ومالي'\r\n\twhen 3 then N'امورواجتماعي'\r\n\twhen 4 then N'بهداشتي ودرماني'\r\n\twhen 5 then N'خدمات'\r\n\twhen 6 then N'کشاورزي'\r\n\twhen 7 then N'فني ومهندسي'\r\n\twhen 8 then N'فنآوري اطلاعات '\r\n\twhen 9 then N'هنرمندان'\r\n\twhen 88 then N'ساير'\r\n\twhen 100 then N'غيرقابل قبول'\r\n\telse ' '\r\n\tend,\r\n YearMonth = YearMonth,\r\n Date = OuterTable.Date,\r\n Employees_Name = Employees_Name,\r\n\tMostakhdemID=MostakhdemID,\r\n Employees_LastName = Employees_LastName,\r\n Employees_Gender = Employees_Gender,\r\n Employees_FatherName = Employees_FatherName,\r\n Employees_NationalCode = Employees_NationalCode,\r\n Employees_IdNo = Employees_IdNo,\r\n Employees_IssuePlace = Employees_IssuePlace,\r\n Employees_Birthplace = Employees_Birthplace,\r\n BirthDate = BirthDate,\r\n MastPaysView_EmpID = MastPaysView_EmpID,\r\n MastPaysView_EduCode = MastPaysView_EduCode,\r\n MastPaysView_EduSubCode = MastPaysView_EduSubCode,\r\n Military = Military,\r\n MastPaysView_Rasteh = MastPaysView_Rasteh,\r\n MastPaysView_Sazpost = MastPaysView_Sazpost,\r\n MastPaysView_Rshteh = MastPaysView_Rshteh,\r\n Rotbeh = Rotbeh,\r\n MastPaysView_Tbgh = MastPaysView_Tbgh,\r\n MastPaysView_MarriageCode = MastPaysView_MarriageCode,\r\n MastPaysView_ChildNo = MastPaysView_ChildNo,\r\n ServiceType = ServiceType,\r\n EmptypePosition = EmptypePosition,\r\n EmpBaseDate = EmpBaseDate,\r\n MastPaysView_IsarCode = MastPaysView_IsarCode,\r\n\tMastPaysView_IsarRelationCode=MastPaysView_IsarRelationCode,\r\n MastPaysView_EmpDate2 = MastPaysView_EmpDate2,\r\n MastPaysView_EmpYear = MastPaysView_EmpYear,\r\n MastPaysView_ChgDate = MastPaysView_ChgDate,\r\n ExemptDate = ExemptDate,\r\n HokmDate = HokmDate,\r\n MadrakEmp = MadrakEmp,\r\n IsarEmp = IsarEmp,\r\n InsType = InsType, \r\n MastPaysView_Salcnd = MastPaysView_Salcnd,\r\n Pay1 = Pay1,\r\n Pay2 = Pay2,\r\n Pay3 = Pay3,\r\n Pay4 = Pay4,\r\n Pay5 = Pay5,\r\n Pay6 = Pay6,\r\n Pay7 = Pay7,\r\n Pay8 = Pay8,\r\n Pay9 = Pay9,\r\n Pay10 = Pay10,\r\n Pay11 = Pay11,\r\n Pay12 = Pay12,\r\n Sayer = Sayer,\r\n Pay13 = Pay13,\r\n\tPay51 = Pay51,\r\n\tPay18Rotbehbandi=Pay18Rotbehbandi,\r\n Pay19Tarmim=Pay19Tarmim,\r\n\tPay46 = Pay46,\r\n Pay14 = Pay14,\r\n SumPay = case WHEN\tMastPaysView_Wrktim IN (2,3) THEN SumPay-(Mogarrari/2)\r\n\t\t\t\t WHEN\tMastPaysView_Wrktim IN (4,5) THEN ROUND(SumPay-(cast (Mogarrari AS FLOAT)/(cast (4 AS FLOAT)/cast (3 AS FLOAT))),0)\r\n\t\t\t ELSE SumPay-Mogarrari\r\n\t\t\t END,\r\n Emp_Baz = Emp_Baz,\r\n Org_Baz = Org_Baz,\r\n MSumPay = MSumPay,\r\n MEmpBaz =MEmpBaz,\r\n MOrgBaz = MOrgBaz,\r\n Code95=Code95,\r\n\tCode97=Code97,\r\n Code96=Code96,\r\n\tJozBBand11=JozBBand11,\r\n Code27=Code27,\r\n Mogarrari = Mogarrari,\r\n SayerOrg = SayerOrg,\r\n SayerEmp = SayerEmp+SayerEmp324+SayerEmp328+SayerEmp308,\r\n\tSayerEmp307=SayerEmp307,\r\n\tSayerEmp308=SayerEmp308,\r\n\tSayerEmp309=SayerEmp309,\r\n SayerEmp313=SayerEmp313,\r\n\tSayerEmp310=SayerEmp310,\r\n\tSayerEmp328=SayerEmp328,\r\n\tPayaaelemandi=Payaaelemandi,\r\n SumKasrBaz = SumKasrBaz,\r\n\tEYear=EYear,\r\n\tEMonth=EMonth,\r\n MastPaysView_Wrktim = MastPaysView_Wrktim,\r\n\tTrialDate,\r\n\t MastPaysView_InsTypeCode = MastPaysView_InsTypeCode,\r\n\t MastPaysView_InsDateUp30=MastPaysView_InsDateUp30,\r\n\ttempPrc =temp.Prc,\r\n\ttempCPrc=temp.CPrc,\r\n\tPay800=Pay800,\r\n\tSumPayWithOutMogharrari=SumPayWithOutMogharrari,\r\n MastPaysView_HokmTypeCode = MastPaysView_HokmTypeCode,\r\n\tPayBackValUnder100=PayBackValUnder100\r\nFrom\r\n (\r\nSELECT\r\nMastPaysView_RegionCode,\r\n BirthDate,\r\n Date,\r\n EmpBaseDate,\r\n Employees_Birthplace,\r\n Employees_FatherName,\r\n Employees_Gender,\r\n Employees_IdNo,\r\n Employees_IssuePlace,\r\n Employees_LastName,\r\n Employees_Name,\r\n\tMostakhdemID,\r\n Employees_NationalCode,\r\n EmptypePosition,\r\n ExemptDate,\r\n HokmDate,\r\n InsType,\r\n IsarEmp,\r\n MadrakEmp,\r\n MastPaysView_ChgDate,\r\n MastPaysView_ChildNo,\r\n MastPaysView_EduCode,\r\n MastPaysView_EduSubCode,\r\n MastPaysView_EmpDate2,\r\n MastPaysView_EmpID,\r\n MastPaysView_EmptypeCode,\r\n MastPaysView_EmpYear,\r\n MastPaysView_IsarCode,\r\n\tMastPaysView_IsarRelationCode,\r\n MastPaysView_MarriageCode,\r\n MastPaysView_Rasteh,\r\n MastPaysView_Rshteh,\r\n MastPaysView_Salcnd,\r\n MastPaysView_Sazpost,\r\n MastPaysView_Tbgh,\r\n Military,\r\n Rotbeh,\r\n ServiceType,\r\n YearMonth,\r\nPayBackValUnder100=Sum(PayBackValUnder100),\r\n\tPay800=SUM(Pay800),\r\n Emp_Baz = Sum(Emp_Baz),\r\n MEmpBaz = Sum(MEmpBaz),\r\n Mogarrari = Sum(Mogarrari),\r\n MOrgBaz = Sum(MOrgBaz),\r\n Code95=Sum(Code95),\r\n\tCode97=Sum(Code97),\r\n Code96=Sum(Code96),\r\n\tJozBBand11=Sum(JozBBand11),\r\n Code27=Sum(Code27),\r\n MSumPay = Sum(MSumPay),\r\n Org_Baz = Sum(Org_Baz),\r\n Pay1 = Sum(Pay1),\r\n Pay10 = Sum(Pay10),\r\n Pay11 = Sum(Pay11),\r\n Pay12 = Sum(Pay12),\r\n Pay13 = Sum(Pay13),\r\n\tPay51 = Sum(Pay51),\r\n\tPay18Rotbehbandi=Sum(Pay18Rotbehbandi),\r\n\tPay19Tarmim=sum(Pay19Tarmim),\r\n\tPay46 =SUM(Pay46),\r\n Pay14 = Sum(Pay14),\r\n Pay2 = Sum(Pay2),\r\n Pay3 = Sum(Pay3),\r\n Pay4 = Sum(Pay4),\r\n Pay5 = Sum(Pay5),\r\n Pay6 = Sum(Pay6),\r\n Pay7 = Sum(Pay7),\r\n Pay8 = Sum(Pay8),\r\n Pay9 = Sum(Pay9),\r\n Sayer = Sum(Sayer),\r\n SayerEmp = Sum(SayerEmp),\r\n\tSayerEmp307=SUM(SayerEmp307),\r\n\tSayerEmp308=SUM(SayerEmp308),\r\n\tSayerEmp309=SUM(SayerEmp309),\r\n SayerEmp313=SUM(SayerEmp313),\r\n\tSayerEmp310=SUM(SayerEmp310),\r\n\tSayerEmp328=Sum(SayerEmp328),\r\n\tPayaaelemandi=sum(Payaaelemandi),\r\n\tSayerEmp324=Sum(SayerEmp324),\r\n SayerOrg = Sum(SayerOrg),\r\n SumKasrBaz = Sum(SumKasrBaz),\r\n SumPay = Sum(SumPay),\r\n\tSumPayWithOutMogharrari = Sum(SumPay),\r\n\tEYear,\r\n\tEMonth,\r\n MastPaysView_Wrktim = MastPaysView_Wrktim,\r\n\t MastPaysView_InsTypeCode = MastPaysView_InsTypeCode,\r\n\t MastPaysView_InsDateUp30=MastPaysView_InsDateUp30,\r\n MastPaysView_HokmTypeCode = MastPaysView_HokmTypeCode,\r\n\tTrialDate\r\nFrom\r\n (\r\nSELECT\r\nMastPaysView_RegionCode=MastPaysView_RegionCode,\r\n BirthDate = BirthDate,\r\n Date = Date,\r\n EmpBaseDate = EmpBaseDate,\r\n Employees_Birthplace = Employees_Birthplace,\r\n Employees_FatherName = Employees_FatherName,\r\n Employees_Gender = Employees_Gender,\r\n Employees_IdNo = Employees_IdNo,\r\n Employees_IssuePlace = Employees_IssuePlace,\r\n Employees_LastName = Employees_LastName,\r\n Employees_Name = Employees_Name,\r\n\tMostakhdemID=MostakhdemID,\r\n Employees_NationalCode = Employees_NationalCode,\r\n EmptypePosition = EmptypePosition,\r\n ExemptDate = ExemptDate,\r\n HokmDate = HokmDate,\r\n InsType = InsType,\r\n IsarEmp = IsarEmp,\r\n MadrakEmp = MadrakEmp,\r\n MastPaysView_ChgDate = MastPaysView_ChgDate,\r\n MastPaysView_ChildNo = MastPaysView_ChildNo,\r\n MastPaysView_EduCode = MastPaysView_EduCode,\r\n MastPaysView_EduSubCode = MastPaysView_EduSubCode,\r\n MastPaysView_EmpDate2 = MastPaysView_EmpDate2,\r\n MastPaysView_EmpID = MastPaysView_EmpID,\r\n MastPaysView_EmptypeCode_ = MastPaysView_EmptypeCode,\r\n MastPaysView_EmpYear = MastPaysView_EmpYear,\r\n MastPaysView_IsarCode = MastPaysView_IsarCode,\r\n\tMastPaysView_IsarRelationCode=MastPaysView_IsarRelationCode,\r\n MastPaysView_MarriageCode = MastPaysView_MarriageCode,\r\n MastPaysView_Rasteh = MastPaysView_Rasteh,\r\n MastPaysView_Rshteh = MastPaysView_Rshteh,\r\n MastPaysView_Salcnd = MastPaysView_Salcnd,\r\n MastPaysView_Sazpost = MastPaysView_Sazpost,\r\n MastPaysView_Tbgh = MastPaysView_Tbgh,\r\n Military = Military,\r\n Rotbeh = Rotbeh,\r\n ServiceType = ServiceType,\r\n YearMonth = YearMonth,\r\n Emp_Baz = Emp_Baz,\r\n MEmpBaz = MEmpBaz,\r\n Mogarrari = Mogarrari,\r\n MOrgBaz = MOrgBaz,\r\n Code95=Code95,\r\n\tCode97=Code97,\r\n Code96=Code96,\r\n\tJozBBand11=JozBBand11,\r\n Code27=Code27,\r\n MSumPay = MSumPay,\r\n\tPay800=Pay800,\r\nPayBackValUnder100=PayBackValUnder100,\r\n Org_Baz = Org_Baz,\r\n Pay1 = Pay1,\r\n Pay10 = Pay10,\r\n Pay11 = Pay11,\r\n Pay12 = Pay12,\r\n Pay13 = Pay13,\r\n\tPay51 = Pay51,\r\n\tPay18Rotbehbandi=Pay18Rotbehbandi,\r\n Pay19Tarmim=Pay19Tarmim,\r\n\tPay46 = Pay46,\r\n Pay14 = Pay14,\r\n Pay2 = Pay2,\r\n Pay3 = Pay3,\r\n Pay4 = Pay4,\r\n Pay5 = Pay5,\r\n Pay6 = Pay6,\r\n Pay7 = Pay7,\r\n Pay8 = Pay8,\r\n Pay9 = Pay9,\r\n Sayer = Sayer,\r\n SayerEmp = SayerEmp,\r\n\tSayerEmp307=SayerEmp307,\r\n\tSayerEmp308=SayerEmp308,\r\n\tSayerEmp309=SayerEmp309,\r\n SayerEmp313=SayerEmp313,\r\n\tSayerEmp310=SayerEmp310,\r\n\tSayerEmp328=SayerEmp328,\r\n\tPayaaelemandi=Payaaelemandi,\r\n\tSayerEmp324=SayerEmp324,\r\n SayerOrg = SayerOrg,\r\n SumKasrBaz = SumKasrBaz,\r\n SumPay = SumPay,\r\n\tEYear=EYear,\r\n\tEMonth=EMonth,\r\n MastPaysView_Wrktim = MastPaysView_Wrktim,\r\n\t MastPaysView_InsTypeCode = MastPaysView_InsTypeCode,\r\n\t MastPaysView_InsDateUp30=MastPaysView_InsDateUp30,\r\n MastPaysView_HokmTypeCode = MastPaysView_HokmTypeCode,\r\n\tTrialDate\r\nFrom\r\n (\r\nSELECT\r\nMastPaysView_RegionCode=MastPaysView_RegionCode,\r\n Emp_Baz = Emp_Baz,\r\n Employees_BirthDate = Employees_BirthDate,\r\n Employees_Birthplace = Employees_Birthplace,\r\n Employees_EmpID = Employees_EmpID,\r\n Employees_FatherName = Employees_FatherName,\r\n Employees_Gender = Employees_Gender,\r\n Employees_IdNo = Employees_IdNo,\r\n Employees_IssuePlace = Employees_IssuePlace,\r\n Employees_LastName = Employees_LastName,\r\n Employees_Name = Employees_Name,\r\n\tMostakhdemID=MostakhdemID,\r\n Employees_NationalCode = Employees_NationalCode,\r\n MastPaysView_ChildNo = MastPaysView_ChildNo,\r\n MastPaysView_EduCode = MastPaysView_EduCode,\r\n MastPaysView_EduSubCode = MastPaysView_EduSubCode,\r\n MastPaysView_EmpID = MastPaysView_EmpID,\r\n MastPaysView_EmptypeCode = MastPaysView_EmptypeCode,\r\n MastPaysView_HokmTypeCode = MastPaysView_HokmTypeCode,\r\n MastPaysView_InsTypeCode = MastPaysView_InsTypeCode,\r\n MastPaysView_IsarCode = MastPaysView_IsarCode,\r\n\tMastPaysView_IsarRelationCode=MastPaysView_IsarRelationCode,\r\n MastPaysView_MarriageCode = MastPaysView_MarriageCode,\r\n MastPaysView_MilitaryStatusCode = MastPaysView_MilitaryStatusCode,\r\n MastPaysView_Mostkhdm = MastPaysView_Mostkhdm,\r\n MastPaysView_Rasteh = MastPaysView_Rasteh,\r\n MastPaysView_Rshteh = MastPaysView_Rshteh,\r\n\tMastPaysView_Salcnd =\tMastPaysView_Wrktim,\r\n MastPaysView_Sazpost = MastPaysView_Sazpost,\r\n MastPaysView_SerialPay = MastPaysView_SerialPay,\r\n MastPaysView_Tbgh = MastPaysView_Tbgh,\r\n MastPaysView_WifeJobCode = MastPaysView_WifeJobCode,\r\n MastPaysView_Wrktim = MastPaysView_Wrktim,\r\n MastPaysView_YearMonth = MastPaysView_YearMonth,\r\n MEmpBaz = MEmpBaz,\r\n Mogarrari = Mogarrari,\r\n MOrgBaz = MOrgBaz,\r\n Code95=Code95,\r\n\tCode97=Code97,\r\n Code96=Code96,\r\n\tJozBBand11=JozBBand11,\r\n Code27=Code27,\r\n\tPay800=Pay800,\r\n PayBackValUnder100=PayBackValUnder100,\r\n MSumPay = Pay800+PayBackValUnder100,\r\n Org_Baz = Org_Baz,\r\n Pay1 = Pay1,\r\n Pay10 = Pay10,\r\n Pay11 = Pay11,\r\n Pay12 = Pay12,\r\n Pay13 = Pay13,\r\n\tPay51 = Pay51,\r\n\tPay18Rotbehbandi=Pay18Rotbehbandi,\r\n Pay19Tarmim=Pay19Tarmim,\r\n\tPay46 = Pay46,\r\n Pay2 = Pay2,\r\n Pay3 = Pay3,\r\n Pay4 = Pay4,\r\n Pay5 = Pay5,\r\n Pay6 = Pay6,\r\n Pay7 = Pay7,\r\n Pay8 = Pay8,\r\n Pay9 = Pay9,\r\n Regions_OrganCode = Regions_OrganCode,\r\n Sayer = Sayer,\r\n SayerEmp = SayerEmp,\r\n\tSayerEmp307=SayerEmp307,\r\n\tSayerEmp308=SayerEmp308,\r\n\tSayerEmp309=SayerEmp309,\r\n SayerEmp313=SayerEmp313,\r\n\tSayerEmp310=SayerEmp310,\r\n\tSayerEmp328 = SayerEmp328,\r\n\tPayaaelemandi=Payaaelemandi,\r\n\tSayerEmp324 = SayerEmp324*(-1),\r\n SayerOrg = SayerOrg,\r\n SumCurrentValues_BackDocVal = SumCurrentValues_BackDocVal,\r\n SumCurrentValues_CodePayID = SumCurrentValues_CodePayID,\r\n SumCurrentValues_DocVal = SumCurrentValues_DocVal,\r\n SumKasrBaz = SumKasrBaz,\r\n SumPay = SumPay,\r\n EmptypePosition = EmptypePosition,\r\n MastPaysView_ChgDate = MastPaysView_ChgDate,\r\n MastPaysView_EmpDate = MastPaysView_EmpDate,\r\n MastPaysView_EmpDate2 = MastPaysView_EmpDate2,\r\n MastPaysView_EmpYear = MastPaysView_EmpYear,\r\n Military = Military,\r\n MastPaysView_Grop = MastPaysView_Grop,\r\n Date = Date,\r\n YearMonth = YearMonth,\r\n BirthDate = BirthDate,\r\n Rotbeh = Rotbeh,\r\n ExemptDate = ExemptDate,\r\n HokmDate = HokmDate,\r\n MadrakEmp = MadrakEmp,\r\n IsarEmp = IsarEmp,\r\n EmpBaseDate = EmpBaseDate,\r\n ServiceType = ServiceType,\r\n InsType = InsType,\r\n MogharariAddi = MogharariAddi,\r\n MogharariJanbaz = MogharariJanbaz,\r\n Pay14 = Pay14,\r\n\tEYear=EYear,\r\n\tEMonth=EMonth,\r\n\tMastPaysView_InsDateUp30=MastPaysView_InsDateUp30,\r\n\tTrialDate\r\nFrom\r\n (\r\nSelect\r\n *\r\nFrom\r\n (\r\nSelect\r\n *,\r\n Sayer = SumPay-Pay1-Pay2-Pay3-Pay4-Pay5-Pay6-Pay7-Pay8-Pay9-Pay10-Pay11-Pay12-Pay51-Pay18Rotbehbandi-Pay19Tarmim-Pay46-Pay800-Code95-Code96-Code97,\r\n SumKasrBaz = 0\r\nFrom\r\n (\r\nSelect\r\n *,\r\n Mogarrari = MogharariAddi+MogharariJanbaz,\r\n SumPay =Pay90 + Pay1+Pay2+Pay3+Pay4+Pay5+Pay6+Pay7+Pay8+Pay9+Pay10+Pay11+Pay12+Pay13+Pay51+Pay18Rotbehbandi+Pay19Tarmim+Code95+Code96+Code97+Code27+Pay46+Pay49,\r\n Pay14 = Pay4+Pay5+Pay6 +Pay49\r\nFrom\r\n (\r\nSelect\r\n (-1)\r\n\telse 0\r\n\tend,\r\n\tPay800 = case\r\nwhen(SumCurrentValues_CodePayID = 801 or SumCurrentValues_CodePayID = 802 or SumCurrentValues_CodePayID = 803 or\r\n\t SumCurrentValues_CodePayID = 804 or SumCurrentValues_CodePayID = 810 or --SumCurrentValues_CodePayID = 813 or\r\n\t SumCurrentValues_CodePayID = 821 or SumCurrentValues_CodePayID = 822 or SumCurrentValues_CodePayID = 824 or SumCurrentValues_CodePayID = 846 or\r\n\t SumCurrentValues_CodePayID = 849 or --SumCurrentValues_CodePayID = 850 or\r\n SumCurrentValues_CodePayID = 825 or SumCurrentValues_CodePayID = 847 or SumCurrentValues_CodePayID = 855 or SumCurrentValues_CodePayID = 845 or\r\n SumCurrentValues_CodePayID = 851 or SumCurrentValues_CodePayID = 857 or SumCurrentValues_CodePayID = 861 or SumCurrentValues_CodePayID = 863 or\r\n \t SumCurrentValues_CodePayID = 866 or SumCurrentValues_CodePayID = 814 or SumCurrentValues_CodePayID = 868 or\r\n \t SumCurrentValues_CodePayID = 886 or SumCurrentValues_CodePayID = 867 or SumCurrentValues_CodePayID = 887 or\r\n SumCurrentValues_CodePayID = 888 OR SumCurrentValues_CodePayID = 877 OR SumCurrentValues_CodePayID = 848 or\r\n \t SumCurrentValues_CodePayID = 891 or SumCurrentValues_CodePayID = 892 or SumCurrentValues_CodePayID = 893 or\r\n\t SumCurrentValues_CodePayID = 894 or SumCurrentValues_CodePayID = 895 or SumCurrentValues_CodePayID = 896 or \r\n SumCurrentValues_CodePayID = 818 or SumCurrentValues_CodePayID = 819 ) \r\n\t then SumCurrentValues_DocVal\r\n\telse 0\r\n\tend,\r\n\tPayBackValUnder100 = case\r\nwhen(SumCurrentValues_CodePayID = 1 or \r\n\t SumCurrentValues_CodePayID = 2 or \r\n\t SumCurrentValues_CodePayID = 3 or \r\n SumCurrentValues_CodePayID = 4 or \r\n SumCurrentValues_CodePayID = 5 or \r\n \t SumCurrentValues_CodePayID = 6 or \r\n \t SumCurrentValues_CodePayID = 10 or \r\n \t --SumCurrentValues_CodePayID = 13 or \r\n\t SumCurrentValues_CodePayID = 14 or \r\n SumCurrentValues_CodePayID = 16 or \r\n\t SumCurrentValues_CodePayID = 18 or \r\n\t SumCurrentValues_CodePayID = 19 or \r\n\t SumCurrentValues_CodePayID = 21 or \r\n\t SumCurrentValues_CodePayID = 22 or \r\n SumCurrentValues_CodePayID = 24 or \r\n SumCurrentValues_CodePayID = 25 or \r\n \t SumCurrentValues_CodePayID = 26 or \r\n \t SumCurrentValues_CodePayID = 30 or \r\n\t SumCurrentValues_CodePayID = 45 or \r\n SumCurrentValues_CodePayID = 47 or \r\n\t SumCurrentValues_CodePayID = 46 or \r\n \t SumCurrentValues_CodePayID = 48 or \r\n\t SumCurrentValues_CodePayID = 49 or\r\n --SumCurrentValues_CodePayID = 50 or \r\n\t SumCurrentValues_CodePayID = 51 or \r\n\t SumCurrentValues_CodePayID = 53 or \r\n\t SumCurrentValues_CodePayID = 54 or \r\n SumCurrentValues_CodePayID = 57 or \r\n SumCurrentValues_CodePayID = 59 or \r\n \t SumCurrentValues_CodePayID = 60 or \r\n \t SumCurrentValues_CodePayID = 61 or \r\n \t SumCurrentValues_CodePayID = 62 or \r\n\t SumCurrentValues_CodePayID = 63 or\r\n SumCurrentValues_CodePayID = 65 or\r\n SumCurrentValues_CodePayID = 66 or\r\n SumCurrentValues_CodePayID = 67 or\r\n SumCurrentValues_CodePayID = 76 or\r\n SumCurrentValues_CodePayID = 77 or\r\n SumCurrentValues_CodePayID = 89 or\r\n SumCurrentValues_CodePayID = 91 or\r\n\t SumCurrentValues_CodePayID = 92 or\r\n SumCurrentValues_CodePayID = 95 or\r\n SumCurrentValues_CodePayID = 96 \r\n )\r\n\t then SumCurrentValues_BackDocVal\r\n\telse 0\r\n\tend,\r\n MOrgBaz =0, \r\n Pay1 = case\r\n\twhen (SumCurrentValues_CodePayID = 1 or SumCurrentValues_CodePayID = 48 or SumCurrentValues_CodePayID = 86 ) then SumCurrentValues_DocVal\r\n\telse 0\r\n\tend,\r\n Org_Baz = 0,\r\n\tIsarEmp=MastPaysView_IsarCode,\r\n Pay6 = case\r\n\twhen (SumCurrentValues_CodePayID = 93 or SumCurrentValues_CodePayID = 893) then SumCurrentValues_DocVal\r\n\telse 0\r\n\tend,\r\n Military = case\r\n\twhen (Employees_Gender = 1 and MastPaysView_MilitaryStatusCode=1) then N'پايان خدمت'\r\n\twhen (Employees_Gender = 1 and MastPaysView_MilitaryStatusCode not in (1,2,3,4,6,7,8,9,10,11)) then N'پايان خدمت'\r\n\twhen (Employees_Gender = 1 and MastPaysView_MilitaryStatusCode in (2,3,4,6,7,8,9,10,11)) then N'معافيت'\r\n\twhen (Employees_Gender != 1 ) then N' '\r\n\telse N' '\r\n\tend,\r\n MogharariJanbaz = case\r\n\twhen (SumCurrentValues_CodePayID = 912) then (SumCurrentValues_DocVal+SumCurrentValues_BackDocVal)\r\n\telse 0\r\n\tend,\r\n SayerOrg = 0,\r\n Date = CASE WHEN (MastPaysView_InsTypeCode=4 OR MastPaysView_InsTypeCode=19 OR MastPaysView_InsTypeCode=28) AND MastPaysView_InsDateUp30=0 THEN CONVERT(varchar(10), @YearMonth) +'01' ELSE MastPaysView_InsDateUp30 end,\r\n YearMonth = @YearMonth,\r\n MadrakEmp = case\r\n\twhen (MastPaysView_EduCode > 18) then 16\r\n\telse MastPaysView_EduCode\r\n\tend,\r\n ExemptDate = case\r\n\twhen (MastPaysView_InsTypeCode = 4 OR MastPaysView_InsTypeCode = 28) then ((MastPaysView_YearMonth)100)+31) AND d.Stepno=0 order by d.YearMonth desc, d.SerialPay desc, d.serial desc),\r\n\tEYear=CASE\r\n WHEN (MastPaysView_EmpYear/100)<10 THEN '0'+CONVERT(varchar(10), MastPaysView_EmpYear/100) \r\n\tELSE CONVERT(varchar(10), MastPaysView_EmpYear/100) \r\n\tEND,\r\n\tEMonth=CASE\r\n WHEN (MastPaysView_EmpYear%100)>=0 AND (MastPaysView_EmpYear%100)<10 THEN '0'+CONVERT(varchar(10), MastPaysView_EmpYear%100) \r\n\tELSE CONVERT(varchar(10), MastPaysView_EmpYear%100) \r\n\tEND\r\nFrom\r\n (\r\nSelect\r\n MastPaysView_InsDateUp30=IsNull(MastPaysView.InsDateUp30,0),\r\n Employees_EmpID=IsNull(Employees.EmpID,0),\r\n Employees_LastName=IsNull(Employees.LastName,N' '),\r\n Employees_Name=IsNull(Employees.Name,N' '),\r\n\tMostakhdemID=IsNull(MastPaysView.Mostkhdm,0),\r\n Employees_FatherName=IsNull(Employees.FatherName,N' '),\r\n Employees_Birthplace=IsNull(Employees.Birthplace,N' '),\r\n Employees_IssuePlace=IsNull(Employees.IssuePlace,N' '),\r\n Employees_BirthDate=IsNull(Employees.BirthDate,0),\r\n Employees_IdNo=IsNull(Employees.IdNo,N' '),\r\n Employees_NationalCode=IsNull(Employees.NationalCode,0),\r\n\tMastPaysView_Rank=IsNull(MastPaysView.Rank,0),\r\n Employees_Gender=IsNull(Employees.Gender,0),\r\n MastPaysView_YearMonth=MastPaysView.YearMonth,\r\n MastPaysView_SerialPay=MastPaysView.SerialPay,\r\n MastPaysView_InsTypeCode=MastPaysView.InsTypeCode,\r\n MastPaysView_Salcnd=MastPaysView.Salcnd,\r\n MastPaysView_Wrktim=MastPaysView.Wrktim,\r\n MastPaysView_RegionCode=MastPaysView.RegionCode,\r\n MastPaysView_EmpID=MastPaysView.EmpID,\r\n MastPaysView_EduCode=MastPaysView.EduCode,\r\n MastPaysView_EduSubCode=MastPaysView.EduSubCode,\r\n MastPaysView_MilitaryStatusCode=MastPaysView.MilitaryStatusCode,\r\n MastPaysView_MarriageCode=MastPaysView.MarriageCode,\r\n MastPaysView_WifeJobCode=MastPaysView.WifeJobCode,\r\n MastPaysView_IsarCode=MastPaysView.IsarCode,\r\n\tMastPaysView_IsarRelationCode=MastPaysView.IsarRelationCode,\r\n MastPaysView_Mostkhdm=MastPaysView.Mostkhdm,\r\n MastPaysView_EmptypeCode=MastPaysView.EmptypeCode,\r\n MastPaysView_Rasteh=MastPaysView.Rasteh,\r\n MastPaysView_Rshteh=MastPaysView.Rshteh,\r\n MastPaysView_Tbgh=MastPaysView.Tbgh,\r\n MastPaysView_Sazpost=MastPaysView.Sazpost,\r\n MastPaysView_HokmTypeCode=MastPaysView.HokmTypeCode,\r\n MastPaysView_ChildNo=MastPaysView.ChildNo,\r\n MastPaysView_EmpYear=MastPaysView.EmpYear,\r\n MastPaysView_EmpDate=ISNULL(MastPaysView.EmpDate,0),\r\n\tMastPaysView_TrialDate=ISNULL(MastPaysView.TrialDate,0),\r\n MastPaysView_EmpDate2=ISNULL(MastPaysView.EmpDate2,0),\r\n MastPaysView_ChgDate=ISNULL(MastPaysView.ChgDate,0),\r\n MastPaysView_Grop=MastPaysView.Grop,\r\n Regions_OrganCode=IsNull(Regions.OrganCode,0),\r\n SumCurrentValues_CodePayID=IsNull(SumCurrentValues.CodePayID,0),\r\n SumCurrentValues_DocVal=IsNull(SumCurrentValues.DocVal,0),\r\n SumCurrentValues_BackDocVal=IsNull(SumCurrentValues.BackDocVal,0),\r\n MastPaysView_CrtDate=MastPaysView.CrtDate,\r\n\tTrialDate = MastPaysView.TrialDate\r\nFrom\r\n \r\nMastPaysView as MastPaysView \r\nLeft Outer Join\r\nSumCurrentValues as SumCurrentValues on MastPaysView.RegionCode = SumCurrentValues.RegionCode and MastPaysView.YearMonth = SumCurrentValues.YearMonth and MastPaysView.SerialPay = SumCurrentValues.SerialPay and MastPaysView.EmpID = SumCurrentValues.EmpID\r\nLeft Outer Join\r\nEmployees as Employees on MastPaysView.EmpID = Employees.EmpID and SumCurrentValues.EmpID = Employees.EmpID\r\nLeft Outer Join\r\nRegions as Regions on MastPaysView.RegionCode = Regions.RegionCode\r\n\r\n) as Table0\r\n\r\n) as Table1\r\n\r\n) as Table2\r\n\r\n) as ConditionTable\r\nWhere\r\n MastPaysView_YearMonth = @YearMonth and\r\nMastPaysView_SerialPay = @SerialPay\r\n\r\n) as UpperLevelTable\r\n\r\n) as SourceTable\r\n\r\n) as InnerTable\r\nGroup BY\r\nMastPaysView_RegionCode,\r\n MastPaysView_Wrktim,\r\n EYear,\r\n EMonth,\r\n BirthDate,\r\n Date,\r\n EmpBaseDate,\r\n Employees_Birthplace,\r\n Employees_FatherName,\r\n Employees_Gender,\r\n Employees_IdNo,\r\n Employees_IssuePlace,\r\n Employees_LastName,\r\n Employees_Name,\r\n\tMostakhdemID,\r\n Employees_NationalCode,\r\n EmptypePosition,\r\n ExemptDate,\r\n HokmDate,\r\n InsType,\r\n IsarEmp,\r\n MadrakEmp,\r\n MastPaysView_ChgDate,\r\n MastPaysView_ChildNo,\r\n MastPaysView_EduCode,\r\n MastPaysView_EduSubCode,\r\n MastPaysView_EmpDate2,\r\n MastPaysView_EmpID,\r\n MastPaysView_EmptypeCode_,\r\n MastPaysView_EmpYear,\r\n MastPaysView_HokmTypeCode,\r\n MastPaysView_IsarCode,\r\n\tMastPaysView_IsarRelationCode,\r\n MastPaysView_MarriageCode,\r\n MastPaysView_Rasteh,\r\n MastPaysView_Rshteh,\r\n MastPaysView_Salcnd,\r\n MastPaysView_Sazpost,\r\n MastPaysView_Tbgh,\r\n Military,\r\n Rotbeh,\r\n ServiceType,\r\n YearMonth, \r\n\tMastPaysView_InsTypeCode,\r\n\tMastPaysView_InsDateUp30,\r\n\tTrialDate\r\n) as OuterTable\r\nleft join temp as temp \r\non OuterTable.InsType= temp.InsBaseTypeCode where temp.rw=1\r\n ) as Outerable2\r\n) as UpperTable\r\n) as UpperTable3\r\n) as UpperTable4\r\n) as UpperTable5\r\n) as UpperTable6\r\n) as UpperTable7\r\nWhere\r\n Mogarrari+Emp_Baz+Org_Baz+SayerOrg+SayerEmp+MEmpBaz+MOrgBaz<> 0 AND UpperTable7.ServiceType<>8\r\n) AS UpperTable8\r\n\t) AS UpperTable9\r\n\t) AS UpperTable10\t\r\n\t--) AS UpperTable11 \r\n\r\n\tSELECT\r\n\tYearMonth = YearMonth,\r\n\tMastPaysView_RegionCode=MastPaysView_RegionCode,\r\n\tMastPaysView_EmpYear=CASE WHEN Emptype2!= 3 and LEN(CONVERT(NVARCHAR(20), MastPaysView_EmpYear))=3 THEN '00/0'+SUBSTRING(CONVERT(NVARCHAR(20), MastPaysView_EmpYear),1,1)+'/'+SUBSTRING(CONVERT(NVARCHAR(20), MastPaysView_EmpYear),2,2)\t\r\n\t\t\t\t\t\t\t WHEN Emptype2!= 3 and LEN(CONVERT(NVARCHAR(20), MastPaysView_EmpYear))=4 THEN '00/' +SUBSTRING(CONVERT(NVARCHAR(20), MastPaysView_EmpYear),1,2)+'/'+SUBSTRING(CONVERT(NVARCHAR(20), MastPaysView_EmpYear),3,2)\r\n\t\t\t\t\t\t\t WHEN Emptype2!= 3 and LEN(CONVERT(NVARCHAR(20), MastPaysView_EmpYear))=5 THEN '0'\t +SUBSTRING(CONVERT(NVARCHAR(20), MastPaysView_EmpYear),1,1)+'/'+SUBSTRING(CONVERT(NVARCHAR(20), MastPaysView_EmpYear),2,2)+'/'+SUBSTRING(CONVERT(NVARCHAR(20), MastPaysView_EmpYear),4,2)\r\n\t\t\t\t\t\t\t WHEN Emptype2!= 3 and LEN(CONVERT(NVARCHAR(20), MastPaysView_EmpYear))=6 THEN\t\t SUBSTRING(CONVERT(NVARCHAR(20), MastPaysView_EmpYear),1,2)+'/'+SUBSTRING(CONVERT(NVARCHAR(20), MastPaysView_EmpYear),3,2)+'/'+SUBSTRING(CONVERT(NVARCHAR(20), MastPaysView_EmpYear),4,2)\r\n\t\t\t\t\t\t\t WHEN Emptype2= 3 THEN ' '\r\n\t\t\t\t\t\t\t ELSE CONVERT(NVARCHAR(20), MastPaysView_EmpYear) END,\t\t \r\n\tEmpBaseDate=EmpBaseDate,\r\n DeductOver30=DeductOver30,\r\n SumDeductIncludeSanavatGhabl=0,\r\n MzoodhengamkosooratbazneshastegiEmpBaz=MzoodhengamkosooratbazneshastegiEmpBaz,\r\n AghsaatEnteghalHaghbime=AghsaatEnteghalHaghbime,\r\n EmpBazSanavatGhbal=0,\r\n OrgBazSanavatghabl=0,\r\n\tJozBBand11=JozBBand11,\r\n\tTafavotTatbigh2=0,\r\n\tTafavotTatbigh3=0,\r\n MostakhdemID=MostakhdemID,\r\n SandoghChangeDate=SandoghChangeDate,\r\n\tSanavatGhairRasmi=CASE WHEN Emptype2= 3 and LEN(CONVERT(NVARCHAR(20), MastPaysView_EmpYear))=3 THEN '00/0'+SUBSTRING(CONVERT(NVARCHAR(20), MastPaysView_EmpYear),1,1)+'/'+SUBSTRING(CONVERT(NVARCHAR(20), MastPaysView_EmpYear),2,2)\t\r\n\t\t\t\t\t\t WHEN Emptype2= 3 and LEN(CONVERT(NVARCHAR(20), MastPaysView_EmpYear))=4 THEN '00/' +SUBSTRING(CONVERT(NVARCHAR(20), MastPaysView_EmpYear),1,2)+'/'+SUBSTRING(CONVERT(NVARCHAR(20), MastPaysView_EmpYear),3,2)\r\n\t\t\t\t\t WHEN Emptype2= 3 and LEN(CONVERT(NVARCHAR(20), MastPaysView_EmpYear))=5 THEN '0'\t +SUBSTRING(CONVERT(NVARCHAR(20), MastPaysView_EmpYear),1,1)+'/'+SUBSTRING(CONVERT(NVARCHAR(20), MastPaysView_EmpYear),2,2)+'/'+SUBSTRING(CONVERT(NVARCHAR(20), MastPaysView_EmpYear),4,2)\r\n\t\t\t\t \t WHEN Emptype2= 3 and LEN(CONVERT(NVARCHAR(20), MastPaysView_EmpYear))=6 THEN\t\t SUBSTRING(CONVERT(NVARCHAR(20), MastPaysView_EmpYear),1,2)+'/'+SUBSTRING(CONVERT(NVARCHAR(20), MastPaysView_EmpYear),3,2)+'/'+SUBSTRING(CONVERT(NVARCHAR(20), MastPaysView_EmpYear),4,2)\r\n\tELSE SanavatGhairRasmi END,\r\n\tMastPaysView_InsDateUp30=MastPaysView_InsDateUp30,\r\n Hokm = Hokm,\r\n Marriage = Marriage,\r\n Reshteh = Reshteh,\r\n Madrak = Madrak,\r\n Major = Major,\r\n Gender = Gender,\r\n\tEmptype = Emptype,\r\n\tEmptype2 = Emptype2,\r\n SazPost = SazPost,\r\n IsarStatus = IsarStatus,\r\n IsarRelStatus = IsarRelStatus,\r\n Rasteh = Rasteh,\r\n Date = Date,\r\n Employees_Name = Employees_Name,\r\n Employees_LastName = Employees_LastName,\r\n Employees_Gender = Employees_Gender,\r\n Employees_FatherName = Employees_FatherName,\r\n Employees_NationalCode = Employees_NationalCode,\r\n Employees_IdNo = Employees_IdNo,\r\n Employees_IssuePlace = Employees_IssuePlace,\r\n Employees_Birthplace = Employees_IssuePlace,\r\n BirthDate =BirthDate,\r\n MastPaysView_EmpID = MastPaysView_EmpID,\r\n MastPaysView_EduCode = MastPaysView_EduCode,\r\n MastPaysView_EduSubCode = MastPaysView_EduSubCode,\r\n Military = Military,\r\n MastPaysView_Rasteh = MastPaysView_Rasteh,\r\n MastPaysView_Sazpost = MastPaysView_Sazpost,\r\n MastPaysView_Rshteh = MastPaysView_Rshteh,\r\n Rotbeh = Rotbeh,\r\n MastPaysView_Tbgh = MastPaysView_Tbgh,\r\n MastPaysView_ChildNo = MastPaysView_ChildNo,\r\n ServiceType = ServiceType,\r\n EmptypePosition = EmptypePosition,\r\n MastPaysView_IsarCode = MastPaysView_IsarCode,\r\n\tMastPaysView_IsarRelationCode=MastPaysView_IsarRelationCode,\r\n MastPaysView_EmpDate2 = MastPaysView_EmpDate2,\r\n MastPaysView_ChgDate = MastPaysView_ChgDate,\r\n HokmDate = HokmDate,\r\n MadrakEmp = MadrakEmp,\r\n MastPaysView_Salcnd = MastPaysView_Salcnd,\r\n\tPhoneNum=PhoneNum,\r\n Pay1 = Pay1,\r\n Pay2 = Pay2,\r\n Pay3 = Pay3,\r\n Pay4 = Pay4,\r\n Pay5 = Pay5,\r\n Pay6 = Pay6,\r\n Pay7 = Pay7,\r\n Pay8 = Pay8,\r\n Pay9 = Pay9,\r\n Pay10 = Pay10,\r\n Pay11 = Pay11,\r\n Pay12 = Pay12,\r\n Sayer = Sayer,\r\n Pay13 = Pay13,\r\n\tPay51 = Pay51,\r\n Pay18Rotbehbandi=Pay18Rotbehbandi,\r\n Pay19Tarmim=Pay19Tarmim,\r\n PayNegahdasht=0,\r\n\tPay46 = Pay46,\r\n Pay14 = Pay14,\r\n SumPay = SumPay,\r\n Emp_Baz =case when Emptype2 IN (19,26) then 0 else Emp_Baz end,\r\n Org_Baz =case when Emptype2 IN (19,26) then Emp_Baz+Org_Baz else Org_Baz end,\r\n MSumPay = MSumPay,\r\n MEmpBaz = MEmpBaz,\r\n MOrgBaz = MOrgBaz,\r\n Code95 = Code95,\r\n\tCode97 = Code97,\r\n Code96 = Code96,\r\n Code27 = Code27,\r\n Mogarrari = Mogarrari,\r\n SayerOrg = SayerOrg,\r\n SayerEmp =SayerEmp,\r\n SumKasrBaz = SumKasrBaz,\r\n\tTrialDate = TrialDate\r\n\tFROM #UpperTable10 --where MastPaysView_EmpID=13178008\r\ndrop table #UpperTable10\r\n";
- Assistant
- User
- Assistant
- User
Msg 319, Level 15, State 1, Line 4 Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
- Assistant
- Assistant
It looks like you didn’t include any specific content in your last message. If you have a question, need further assistance, or require clarification on the previous SQL conversion, please feel free to ask! I'm here to help.
- User
Msg 156, Level 15, State 1, Line 128 Incorrect syntax near the keyword 'FROM'. Msg 156, Level 15, State 1, Line 234 Incorrect syntax near the keyword 'AS'.
- Assistant
- User
i run it in SSMS, please fix it :
Msg 156, Level 15, State 1, Line 138 Incorrect syntax near the keyword 'SELECT'.
- Assistant
- User
- Assistant
- User
- Assistant