0
if
@Status = '0' and @Complaint<> '0'
WITH NewTable As
(
Select sno = ROW_NUMBER()OVER (order by complaint_id), Complaint_Id, Complaint.ComplaintType_id, Complaint.complaintProfileId, Complaint.Description,
Complaint.Email, Complaint.PriorityLevel_id, Complaint.Date_Complained, Complaint.Status, Complaint.AdminComments, Complaint.Phone, Complaint.Evidence
from Complaints Complaint),
with two as
if exists(select profile_id from MMBmembership
where profile_id = ComplaintProfileId)
select MMB_Name as @Name from MMB_BusinessProfiles where MMBId= (select MMB_id from MMBMembership
where profile_id = ComplaintProfileId)
if exists(select profile_id from UPPMembership
where profile_id = ComplaintProfileId)
set @Name = 'UPP'
else
set @name = 'Not Found'
SELECT * FROM NewTable,@Name left outer join two on
newtable.complaintProfileid = two.ProfileId
WHERE (ComplaintType_id = @Complaint) ORDER BY Date_Complained desc ,PriorityLevel_id
Thanks
Sun