-3
Create PROCEDURE [dbo].[USP_ViewRejectedReport24102014] (
@Pvch_AdvertisementNo VARCHAR(200)
,@Pvch_Post_Code VARCHAR(100)
,@Pint_DistrictId INT
,@PintType INT
)
AS
DECLARE @Remarks VARCHAR(max)
SET @Remarks = (
SELECT distinct C.vch_Remarks
FROM T_CAF_Receive C,T_ApplicantDetails_Temp A
WHERE C.vch_uniquerefno =A.vch_uniquerefno AND ISNULL(c.bit_DeletedFlag, 0) = 0
)
BEGIN
IF (@PintType = 1)
BEGIN
IF (@Pint_DistrictId = 0)
BEGIN
SELECT A.int_ApplicantId
,A.vch_UniqueRefNo
,A.vch_ApplicantName
,CASE int_Gender
WHEN 1
THEN 'Male'
WHEN 2
THEN 'Female'
END AS Gender
,vch_CorHouseNo
,(
SELECT vch_DistrictName
FROM M_District
WHERE int_DistrictID = A.int_CorDistID
AND int_StateID = A.int_CorStateID
) District
,vch_CorPinCode
,dtm_DOB
,(
CASE int_CategoryId
WHEN 1
THEN 'UR'
WHEN 2
THEN 'SC'
WHEN 3
THEN 'ST'
WHEN 4
THEN 'SEBC'
END
) Category
,(
CASE isnull(bit_PHOH, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) PWD
,(
CASE isnull(bit_SportsPerson, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) SportsPerson
,(
CASE isnull(bit_ESM, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) ESM
,(
CASE isnull(bit_Odia, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) Odia
,(
SELECT vch_DDNO
FROM T_Finance_Details F
WHERE isnull(F.bit_DeletedFlag, 0) = 0
AND F.vch_uniquerefno = A.vch_uniquerefno
) vch_DDNO
,A.vch_CorMobileNo
,(
CASE @Remarks
WHEN NULL
THEN (
SELECT vch_Remarks
FROM T_CAF_Receive C
WHERE C.vch_UniqueRefNo = A.vch_UniqueRefNo
AND ISNULL(c.bit_DeletedFlag, 0) = 0
)
ELSE (
SELECT STUFF((
SELECT vch_remarks
FROM M_remark_detail
WHERE int_remark_id IN (
SELECT val
FROM UDF_Split((
SELECT vch_remarks
FROM T_caf_receive C
WHERE C.vch_uniquerefno = A.vch_uniquerefno
), ',')
)
FOR XML PATH('')
), 1, 1, '')
)
END
) Remarks
,(
CASE isnull(A.bit_ReceiveStatus, 0)
WHEN 1
THEN '1'
ELSE '0'
END
) ReceiveStatus
FROM T_ApplicantDetails_Temp A
WHERE isnull(A.bit_DeletedFlag, 0) = 0
AND ISNULL(A.bit_ReceiveStatus, 0) = 1
AND ISNULL(A.bit_Rejected, 0) = 1
AND isnull(A.bit_DuplicateStatus, 0) = 0
AND A.vch_AdvertisementNo = @Pvch_AdvertisementNo
AND A.vch_Post_Code = @Pvch_Post_Code
ORDER BY A.vch_UniqueRefNo
END
ELSE
BEGIN
SELECT A.int_ApplicantId
,A.vch_UniqueRefNo
,A.vch_ApplicantName
,CASE int_Gender
WHEN 1
THEN 'Male'
WHEN 2
THEN 'Female'
END AS Gender
,vch_CorHouseNo
,(
SELECT vch_DistrictName
FROM M_District
WHERE int_DistrictID = A.int_CorDistID
AND int_StateID = A.int_CorStateID
) District
,vch_CorPinCode
,dtm_DOB
,(
CASE int_CategoryId
WHEN 1
THEN 'UR'
WHEN 2
THEN 'SC'
WHEN 3
THEN 'ST'
WHEN 4
THEN 'SEBC'
END
) Category
,(
CASE isnull(bit_PHOH, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) PWD
,(
CASE isnull(bit_SportsPerson, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) SportsPerson
,(
CASE isnull(bit_ESM, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) ESM
,(
CASE isnull(bit_Odia, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) Odia
,(
SELECT vch_DDNO
FROM T_Finance_Details F
WHERE isnull(F.bit_DeletedFlag, 0) = 0
AND F.vch_uniquerefno = A.vch_uniquerefno
) vch_DDNO
,A.vch_CorMobileNo
,(
CASE @Remarks
WHEN NULL
THEN (
SELECT vch_Remarks
FROM T_CAF_Receive C
WHERE C.vch_UniqueRefNo = A.vch_UniqueRefNo
AND ISNULL(c.bit_DeletedFlag, 0) = 0
)
ELSE (
SELECT STUFF((
SELECT vch_remarks
FROM M_remark_detail
WHERE int_remark_id IN (
SELECT val
FROM UDF_Split((
SELECT vch_remarks
FROM T_caf_receive C
WHERE C.vch_uniquerefno = A.vch_uniquerefno
), ',')
)
FOR XML PATH('')
), 1, 1, '')
)
END
) Remarks
,(
CASE isnull(A.bit_ReceiveStatus, 0)
WHEN 1
THEN '1'
ELSE '0'
END
) ReceiveStatus
FROM T_ApplicantDetails_Temp A
WHERE isnull(A.bit_DeletedFlag, 0) = 0
AND ISNULL(A.bit_ReceiveStatus, 0) = 1
AND ISNULL(A.bit_Rejected, 0) = 1
AND isnull(A.bit_DuplicateStatus, 0) = 0
AND A.vch_AdvertisementNo = @Pvch_AdvertisementNo
AND A.vch_Post_Code = @Pvch_Post_Code
AND A.int_examDistrictId = @Pint_DistrictId
ORDER BY A.vch_UniqueRefNo
END
END
ELSE IF (@PintType = 2)
BEGIN
IF (@Pint_DistrictId = 0)
BEGIN
SELECT A.int_ApplicantId
,A.vch_UniqueRefNo
,A.vch_ApplicantName
,CASE int_Gender
WHEN 1
THEN 'Male'
WHEN 2
THEN 'Female'
END AS Gender
,vch_CorHouseNo
,(
SELECT vch_DistrictName
FROM M_District
WHERE int_DistrictID = A.int_CorDistID
AND int_StateID = A.int_CorStateID
) District
,vch_CorPinCode
,dtm_DOB
,(
CASE int_CategoryId
WHEN 1
THEN 'UR'
WHEN 2
THEN 'SC'
WHEN 3
THEN 'ST'
WHEN 4
THEN 'SEBC'
END
) Category
,(
CASE isnull(bit_PHOH, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) PWD
,(
CASE isnull(bit_SportsPerson, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) SportsPerson
,(
CASE isnull(bit_ESM, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) ESM
,(
CASE isnull(bit_Odia, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) Odia
,(
SELECT vch_DDNO
FROM T_Finance_Details F
WHERE isnull(F.bit_DeletedFlag, 0) = 0
AND F.vch_uniquerefno = A.vch_uniquerefno
) vch_DDNO
,A.vch_CorMobileNo
,CASE @Remarks
WHEN NULL
THEN (
SELECT vch_Remarks
FROM T_CAF_Receive C
WHERE C.vch_UniqueRefNo = A.vch_UniqueRefNo
AND ISNULL(c.bit_DeletedFlag, 0) = 0
)
ELSE (
SELECT STUFF((
SELECT vch_remarks
FROM M_remark_detail
WHERE int_remark_id IN (
SELECT val
FROM UDF_Split((
SELECT vch_remarks
FROM T_caf_receive C
WHERE C.vch_uniquerefno = A.vch_uniquerefno
), ',')
)
FOR XML PATH('')
), 1, 1, '')
)
END
,(
CASE isnull(A.bit_ReceiveStatus, 0)
WHEN 1
THEN '1'
ELSE '0'
END
) ReceiveStatus
FROM T_ApplicantDetails_Temp A
WHERE isnull(A.bit_DeletedFlag, 0) = 0
AND ISNULL(A.bit_ReceiveStatus, 0) = 1
AND ISNULL(A.bit_Rejected, 0) = 1
AND isnull(A.bit_DuplicateStatus, 0) = 0
AND A.vch_AdvertisementNo = @Pvch_AdvertisementNo
AND A.vch_Post_Code = @Pvch_Post_Code
ORDER BY A.vch_UniqueRefNo
END
ELSE
BEGIN
SELECT A.int_ApplicantId
,A.vch_UniqueRefNo
,A.vch_ApplicantName
,CASE int_Gender
WHEN 1
THEN 'Male'
WHEN 2
THEN 'Female'
END AS Gender
,vch_CorHouseNo
,(
SELECT vch_DistrictName
FROM M_District
WHERE int_DistrictID = A.int_CorDistID
AND int_StateID = A.int_CorStateID
) District
,vch_CorPinCode
,dtm_DOB
,(
CASE int_CategoryId
WHEN 1
THEN 'UR'
WHEN 2
THEN 'SC'
WHEN 3
THEN 'ST'
WHEN 4
THEN 'SEBC'
END
) Category
,(
CASE isnull(bit_PHOH, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) PWD
,(
CASE isnull(bit_SportsPerson, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) SportsPerson
,(
CASE isnull(bit_ESM, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) ESM
,(
CASE isnull(bit_Odia, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) Odia
,(
SELECT vch_DDNO
FROM T_Finance_Details F
WHERE isnull(F.bit_DeletedFlag, 0) = 0
AND F.vch_uniquerefno = A.vch_uniquerefno
) vch_DDNO
,A.vch_CorMobileNo
,(
CASE @Remarks
WHEN NULL
THEN (
SELECT vch_Remarks
FROM T_CAF_Receive C
WHERE C.vch_UniqueRefNo = A.vch_UniqueRefNo
AND ISNULL(c.bit_DeletedFlag, 0) = 0
)
ELSE (
SELECT STUFF((
SELECT vch_remarks
FROM M_remark_detail
WHERE int_remark_id IN (
SELECT val
FROM UDF_Split((
SELECT vch_remarks
FROM T_caf_receive C
WHERE C.vch_uniquerefno = A.vch_uniquerefno
), ',')
)
FOR XML PATH('')
), 1, 1, '')
)
END
) Remarks
,(
CASE isnull(A.bit_ReceiveStatus, 0)
WHEN 1
THEN '1'
ELSE '0'
END
) ReceiveStatus
FROM T_ApplicantDetails_Temp A
WHERE isnull(A.bit_DeletedFlag, 0) = 0
AND ISNULL(A.bit_ReceiveStatus, 0) = 1
AND ISNULL(A.bit_Rejected, 0) = 1
AND isnull(A.bit_DuplicateStatus, 0) = 0
AND A.vch_AdvertisementNo = @Pvch_AdvertisementNo
AND A.vch_Post_Code = @Pvch_Post_Code
AND A.int_examDistrictId = @Pint_DistrictId
ORDER BY A.vch_UniqueRefNo
END
END
ELSE IF (@PintType = 3)
BEGIN
IF (@Pint_DistrictId = 0)
BEGIN
SELECT A.int_ApplicantId
,A.vch_UniqueRefNo
,A.vch_ApplicantName
,CASE int_Gender
WHEN 1
THEN 'Male'
WHEN 2
THEN 'Female'
END AS Gender
,vch_CorHouseNo
,(
SELECT vch_DistrictName
FROM M_District
WHERE int_DistrictID = A.int_CorDistID
AND int_StateID = A.int_CorStateID
) District
,vch_CorPinCode
,dtm_DOB
,(
CASE int_CategoryId
WHEN 1
THEN 'UR'
WHEN 2
THEN 'SC'
WHEN 3
THEN 'ST'
WHEN 4
THEN 'SEBC'
END
) Category
,(
CASE isnull(bit_PHOH, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) PWD
,(
CASE isnull(bit_SportsPerson, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) SportsPerson
,(
CASE isnull(bit_ESM, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) ESM
,(
CASE isnull(bit_Odia, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) Odia
,(
SELECT vch_DDNO
FROM T_Finance_Details F
WHERE isnull(F.bit_DeletedFlag, 0) = 0
AND F.vch_uniquerefno = A.vch_uniquerefno
) vch_DDNO
,A.vch_CorMobileNo
,CASE @Remarks
WHEN NULL
THEN (
SELECT vch_Remarks
FROM T_CAF_Receive C
WHERE C.vch_UniqueRefNo = A.vch_UniqueRefNo
AND ISNULL(c.bit_DeletedFlag, 0) = 0
)
ELSE (
SELECT STUFF((
SELECT vch_remarks
FROM M_remark_detail
WHERE int_remark_id IN (
SELECT val
FROM UDF_Split((
SELECT vch_remarks
FROM T_caf_receive C
WHERE C.vch_uniquerefno = A.vch_uniquerefno
), ',')
)
FOR XML PATH('')
), 1, 1, '')
)
END
,(
CASE isnull(A.bit_ReceiveStatus, 0)
WHEN 1
THEN '1'
ELSE '0'
END
) ReceiveStatus
FROM T_ApplicantDetails_Temp A
WHERE isnull(A.bit_DeletedFlag, 0) = 0
AND ISNULL(A.bit_ReceiveStatus, 0) = 1
AND ISNULL(A.bit_Rejected, 0) = 1
AND isnull(A.bit_DuplicateStatus, 0) = 0
AND A.vch_AdvertisementNo = @Pvch_AdvertisementNo
AND A.vch_Post_Code = @Pvch_Post_Code
ORDER BY A.vch_UniqueRefNo
END
ELSE
BEGIN
SELECT A.int_ApplicantId
,A.vch_UniqueRefNo
,A.vch_ApplicantName
,CASE int_Gender
WHEN 1
THEN 'Male'
WHEN 2
THEN 'Female'
END AS Gender
,vch_CorHouseNo
,(
SELECT vch_DistrictName
FROM M_District
WHERE int_DistrictID = A.int_CorDistID
AND int_StateID = A.int_CorStateID
) District
,vch_CorPinCode
,dtm_DOB
,(
CASE int_CategoryId
WHEN 1
THEN 'UR'
WHEN 2
THEN 'SC'
WHEN 3
THEN 'ST'
WHEN 4
THEN 'SEBC'
END
) Category
,(
CASE isnull(bit_PHOH, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) PWD
,(
CASE isnull(bit_SportsPerson, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) SportsPerson
,(
CASE isnull(bit_ESM, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) ESM
,(
CASE isnull(bit_Odia, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) Odia
,(
SELECT vch_DDNO
FROM T_Finance_Details F
WHERE isnull(F.bit_DeletedFlag, 0) = 0
AND F.vch_uniquerefno = A.vch_uniquerefno
) vch_DDNO
,A.vch_CorMobileNo
,(
CASE @Remarks
WHEN NULL
THEN (
SELECT vch_Remarks
FROM T_CAF_Receive C
WHERE C.vch_UniqueRefNo = A.vch_UniqueRefNo
AND ISNULL(c.bit_DeletedFlag, 0) = 0
)
ELSE (
SELECT STUFF((
SELECT vch_remarks
FROM M_remark_detail
WHERE int_remark_id IN (
SELECT val
FROM UDF_Split((
SELECT vch_remarks
FROM T_caf_receive C
WHERE C.vch_uniquerefno = A.vch_uniquerefno
), ',')
)
FOR XML PATH('')
), 1, 1, '')
)
END
) Remarks
,(
CASE isnull(A.bit_ReceiveStatus, 0)
WHEN 1
THEN '1'
ELSE '0'
END
) ReceiveStatus
FROM T_ApplicantDetails_Temp A
WHERE isnull(A.bit_DeletedFlag, 0) = 0
AND ISNULL(A.bit_ReceiveStatus, 0) = 1
AND ISNULL(A.bit_Rejected, 0) = 1
AND isnull(A.bit_DuplicateStatus, 0) = 0
AND A.vch_AdvertisementNo = @Pvch_AdvertisementNo
AND A.vch_Post_Code = @Pvch_Post_Code
AND A.int_examDistrictId = @Pint_DistrictId
ORDER BY A.vch_UniqueRefNo
END
END
ELSE IF (@PintType = 4)
BEGIN
IF (@Pint_DistrictId = 0)
BEGIN
SELECT A.int_ApplicantId
,A.vch_UniqueRefNo
,A.vch_ApplicantName
,CASE int_Gender
WHEN 1
THEN 'Male'
WHEN 2
THEN 'Female'
END AS Gender
,vch_CorHouseNo
,(
SELECT vch_DistrictName
FROM M_District
WHERE int_DistrictID = A.int_CorDistID
AND int_StateID = A.int_CorStateID
) District
,vch_CorPinCode
,dtm_DOB
,(
CASE int_CategoryId
WHEN 1
THEN 'UR'
WHEN 2
THEN 'SC'
WHEN 3
THEN 'ST'
WHEN 4
THEN 'SEBC'
END
) Category
,(
CASE isnull(bit_PHOH, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) PWD
,(
CASE isnull(bit_SportsPerson, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) SportsPerson
,(
CASE isnull(bit_ESM, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) ESM
,(
CASE isnull(bit_Odia, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) Odia
,(
SELECT vch_DDNO
FROM T_Finance_Details F
WHERE isnull(F.bit_DeletedFlag, 0) = 0
AND F.vch_uniquerefno = A.vch_uniquerefno
) vch_DDNO
,A.vch_CorMobileNo
,CASE @Remarks
WHEN NULL
THEN (
SELECT vch_Remarks
FROM T_CAF_Receive C
WHERE C.vch_UniqueRefNo = A.vch_UniqueRefNo
AND ISNULL(c.bit_DeletedFlag, 0) = 0
)
ELSE (
SELECT STUFF((
SELECT vch_remarks
FROM M_remark_detail
WHERE int_remark_id IN (
SELECT val
FROM UDF_Split((
SELECT vch_remarks
FROM T_caf_receive C
WHERE C.vch_uniquerefno = A.vch_uniquerefno
), ',')
)
FOR XML PATH('')
), 1, 1, '')
)
END
,(
CASE isnull(A.bit_ReceiveStatus, 0)
WHEN 1
THEN '1'
ELSE '0'
END
) ReceiveStatus
FROM T_ApplicantDetails_Temp A
WHERE isnull(A.bit_DeletedFlag, 0) = 0
AND ISNULL(A.bit_ReceiveStatus, 0) = 1
AND ISNULL(A.bit_Rejected, 0) = 1
AND isnull(A.bit_DuplicateStatus, 0) = 0
AND A.vch_AdvertisementNo = @Pvch_AdvertisementNo
AND A.vch_Post_Code = @Pvch_Post_Code
ORDER BY A.vch_UniqueRefNo
END
ELSE
BEGIN
SELECT A.int_ApplicantId
,A.vch_UniqueRefNo
,A.vch_ApplicantName
,CASE int_Gender
WHEN 1
THEN 'Male'
WHEN 2
THEN 'Female'
END AS Gender
,vch_CorHouseNo
,(
SELECT vch_DistrictName
FROM M_District
WHERE int_DistrictID = A.int_CorDistID
AND int_StateID = A.int_CorStateID
) District
,vch_CorPinCode
,dtm_DOB
,(
CASE int_CategoryId
WHEN 1
THEN 'UR'
WHEN 2
THEN 'SC'
WHEN 3
THEN 'ST'
WHEN 4
THEN 'SEBC'
END
) Category
,(
CASE isnull(bit_PHOH, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) PWD
,(
CASE isnull(bit_SportsPerson, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) SportsPerson
,(
CASE isnull(bit_ESM, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) ESM
,(
CASE isnull(bit_Odia, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) Odia
,(
SELECT vch_DDNO
FROM T_Finance_Details F
WHERE isnull(F.bit_DeletedFlag, 0) = 0
AND F.vch_uniquerefno = A.vch_uniquerefno
) vch_DDNO
,A.vch_CorMobileNo
,(
CASE @Remarks
WHEN NULL
THEN (
SELECT vch_Remarks
FROM T_CAF_Receive C
WHERE C.vch_UniqueRefNo = A.vch_UniqueRefNo
AND ISNULL(c.bit_DeletedFlag, 0) = 0
)
ELSE (
SELECT STUFF((
SELECT vch_remarks
FROM M_remark_detail
WHERE int_remark_id IN (
SELECT val
FROM UDF_Split((
SELECT vch_remarks
FROM T_caf_receive C
WHERE C.vch_uniquerefno = A.vch_uniquerefno
), ',')
)
FOR XML PATH('')
), 1, 1, '')
)
END
) Remarks
,(
CASE isnull(A.bit_ReceiveStatus, 0)
WHEN 1
THEN '1'
ELSE '0'
END
) ReceiveStatus
FROM T_ApplicantDetails_Temp A
WHERE isnull(A.bit_DeletedFlag, 0) = 0
AND ISNULL(A.bit_ReceiveStatus, 0) = 1
AND ISNULL(A.bit_Rejected, 0) = 1
AND isnull(A.bit_DuplicateStatus, 0) = 0
AND A.vch_AdvertisementNo = @Pvch_AdvertisementNo
AND A.vch_Post_Code = @Pvch_Post_Code
AND A.int_examDistrictId = @Pint_DistrictId
ORDER BY A.vch_UniqueRefNo
END
END
ELSE
BEGIN
IF (@Pint_DistrictId = 0)
BEGIN
SELECT A.int_ApplicantId
,A.vch_UniqueRefNo
,A.vch_ApplicantName
,CASE int_Gender
WHEN 1
THEN 'Male'
WHEN 2
THEN 'Female'
END AS Gender
,vch_CorHouseNo
,(
SELECT vch_DistrictName
FROM M_District
WHERE int_DistrictID = A.int_CorDistID
AND int_StateID = A.int_CorStateID
) District
,vch_CorPinCode
,dtm_DOB
,(
CASE int_CategoryId
WHEN 1
THEN 'UR'
WHEN 2
THEN 'SC'
WHEN 3
THEN 'ST'
WHEN 4
THEN 'SEBC'
END
) Category
,(
CASE isnull(bit_PHOH, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) PWD
,(
CASE isnull(bit_SportsPerson, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) SportsPerson
,(
CASE isnull(bit_ESM, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) ESM
,(
CASE isnull(bit_Odia, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) Odia
,(
SELECT vch_DDNO
FROM T_Finance_Details F
WHERE isnull(F.bit_DeletedFlag, 0) = 0
AND F.vch_uniquerefno = A.vch_uniquerefno
) vch_DDNO
,A.vch_CorMobileNo
,CASE @Remarks
WHEN NULL
THEN (
SELECT vch_Remarks
FROM T_CAF_Receive C
WHERE C.vch_UniqueRefNo = A.vch_UniqueRefNo
AND ISNULL(c.bit_DeletedFlag, 0) = 0
)
ELSE (
SELECT STUFF((
SELECT vch_remarks
FROM M_remark_detail
WHERE int_remark_id IN (
SELECT val
FROM UDF_Split((
SELECT vch_remarks
FROM T_caf_receive C
WHERE C.vch_uniquerefno = A.vch_uniquerefno
), ',')
)
FOR XML PATH('')
), 1, 1, '')
)
END
,(
CASE isnull(A.bit_ReceiveStatus, 0)
WHEN 1
THEN '1'
ELSE '0'
END
) ReceiveStatus
FROM T_ApplicantDetails_Temp A
WHERE isnull(A.bit_DeletedFlag, 0) = 0
AND ISNULL(A.bit_ReceiveStatus, 0) = 1
AND ISNULL(A.bit_Rejected, 0) = 1
AND isnull(A.bit_DuplicateStatus, 0) = 0
AND A.vch_AdvertisementNo = @Pvch_AdvertisementNo
AND A.vch_Post_Code = @Pvch_Post_Code
ORDER BY A.vch_UniqueRefNo
END
ELSE
BEGIN
SELECT A.int_ApplicantId
,A.vch_UniqueRefNo
,A.vch_ApplicantName
,CASE int_Gender
WHEN 1
THEN 'Male'
WHEN 2
THEN 'Female'
END AS Gender
,vch_CorHouseNo
,(
SELECT vch_DistrictName
FROM M_District
WHERE int_DistrictID = A.int_CorDistID
AND int_StateID = A.int_CorStateID
) District
,vch_CorPinCode
,dtm_DOB
,(
CASE int_CategoryId
WHEN 1
THEN 'UR'
WHEN 2
THEN 'SC'
WHEN 3
THEN 'ST'
WHEN 4
THEN 'SEBC'
END
) Category
,(
CASE isnull(bit_PHOH, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) PWD
,(
CASE isnull(bit_SportsPerson, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) SportsPerson
,(
CASE isnull(bit_ESM, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) ESM
,(
CASE isnull(bit_Odia, 0)
WHEN 1
THEN 'Yes'
ELSE 'No'
END
) Odia
,(
SELECT vch_DDNO
FROM T_Finance_Details F
WHERE isnull(F.bit_DeletedFlag, 0) = 0
AND F.vch_uniquerefno = A.vch_uniquerefno
) vch_DDNO
,A.vch_CorMobileNo
,(
CASE @Remarks
WHEN NULL
THEN (
SELECT vch_Remarks
FROM T_CAF_Receive C
WHERE C.vch_UniqueRefNo = A.vch_UniqueRefNo
AND ISNULL(c.bit_DeletedFlag, 0) = 0
)
ELSE (
SELECT STUFF((
SELECT vch_remarks
FROM M_remark_detail
WHERE int_remark_id IN (
SELECT val
FROM UDF_Split((
SELECT vch_remarks
FROM T_caf_receive C
WHERE C.vch_uniquerefno = A.vch_uniquerefno
), ',')
)
FOR XML PATH('')
), 1, 1, '')
)
END
) Remarks
,(
CASE isnull(A.bit_ReceiveStatus, 0)
WHEN 1
THEN '1'
ELSE '0'
END
) ReceiveStatus
FROM T_ApplicantDetails_Temp A
WHERE isnull(A.bit_DeletedFlag, 0) = 0
AND ISNULL(A.bit_ReceiveStatus, 0) = 1
AND ISNULL(A.bit_Rejected, 0) = 1
AND isnull(A.bit_DuplicateStatus, 0) = 0
AND A.vch_AdvertisementNo = @Pvch_AdvertisementNo
AND A.vch_Post_Code = @Pvch_Post_Code
AND A.int_examDistrictId = @Pint_DistrictId
ORDER BY A.vch_UniqueRefNo
END
END
END
질문을 작성하십시오. {} 버튼을 사용할 수 있습니다. – WadimX
대부분의 경우 비고가 채워집니다. @Remarks 변수를 채우는 쿼리를 실행하면 얼마나 많은 레코드가 표시됩니까? – Mez