SQLTeam.com | Weblogs | Forums

Facing issue while returning true or false

Could you please tell me how can I return true false while deleting w/o using any id.
I have tried in this way..
.
DELETE FROM HR_EMPBUWISETRANSFER WHERE ID =(SELECT T2.ID FROM (SELECT EMPCODE,MAX(ID) ID FROM HR_EMPBUWISETRANSFER GROUP BY EMPCODE) T1
INNER JOIN HR_EMPBUWISETRANSFER T2 ON T1.ID = T2.ID WHERE T2.EMPCODE = @P_EMPCODE AND T2.CURRENTBU = @p_CURRENTBUCODE )

		--MONTHPERIODCODE=@P_MONTHPERIODCODE AND BUSINESSUNITCODE=@P_BUSINESUNITCODE AND PAYSTRUCTURECODE=@P_PAYSTRUCTCODE
		--(SELECT T2.ID FROM (SELECT EMPCODE,MAX(ID) ID FROM HR_EMPBUWISETRANSFER GROUP BY EMPCODE) T1

-- INNER JOIN HR_EMPBUWISETRANSFER T2 ON T1.ID = T2.ID WHERE T2.EMPCODE = @P_EMPCODE AND T2.CURRENTBU = @p_CURRENTBUCODE)
Declare @result BIT
SET @result = 0

         RETURN (@result)

you can use @@RowCount to return true of false

Please write it in code
Rowcount will give count of rows.

True or false indicating what?

if @@rowcount = 0 
    return 0
else 
   return 1

if count is related to how many were deleted you could try

Declare @result BIT

declare @deleted  table(ID int);


DELETE FROM HR_EMPBUWISETRANSFER 
OUTPUT deleted.ID into @deleted
 WHERE ID = (
   SELECT T2.ID 
     FROM (SELECT EMPCODE,MAX(ID) ID 
	        FROM HR_EMPBUWISETRANSFER 
		   GROUP BY EMPCODE
		  ) T1
  INNER JOIN HR_EMPBUWISETRANSFER T2 ON T1.ID = T2.ID 
  WHERE T2.EMPCODE = @P_EMPCODE 
    AND T2.CURRENTBU = @p_CURRENTBUCODE 
	)

;with gumbo
as
(
	select count(1) as cnt
	  from @deleted
)
select @result = 
	case 
	   when gumbo.cnt >  0 then 1
	   else 0
	end
from gumbo

return @result

Now I am facing in front end while deletion....The condition is, if an employeee is transfered to new branch then can employee can be deleted otherwise if it shows previous branch then it will show an alert("Child record Exists ")...But in my scenario its everytime returning true value.I really got stuck from last 2 days. Please help me if u can.
Its coded like this :
if (count == 0)
{
RadAjaxManager1.Alert("Please Choose Business Unit");
return;
}

            status = objSiteWiseAttendance.DeleteEmpSiteWiseAttendance(Session["ConnectionInfo"].ToString(), Session["Provider"].ToString(), Convert.ToInt32(txtMonth.Text), dsData, Convert.ToString(rcBusinessUnit.Value), Convert.ToString(rcCompany.Value));
        
        if (status == false)
        {
            RadAjaxManager1.Alert("Unable_To_Delete_Record_Child_Record_Exists");
            return;
        }

First off, was your first problem resolved or not?