This is my stored procedure
CREATE OR ALTER PROCEDURE [dbo].[sp_TADashboardVoid]
@PartnerId INT,
@UserId BIGINT,
@TAType INT = 0,
@Borough INT = 0,
@LandlordId INT = 0,
@AllocationStartDate DATE = NULL,
@AllocationEndDate DATE = NULL,
@PropertyRef VARCHAR(100) = NULL,
@PropertyType INT = 0,
@PropertyId VARCHAR(100) = NULL,
@PropertyAddress VARCHAR(200) = NULL,
-- @LandlordProperty VARCHAR(100) = NULL
@PropertyStatusId INT = NULL,
@HouseholdId VARCHAR(10) = NULL,
@ReferenceID VARCHAR(50) = NULL,
@VoidStartDate DATE = NULL,
@VoidEndDate DATE = NULL
AS
BEGIN
DECLARE @demotest TABLE (
PropertyID NVARCHAR(MAX)
,App_id INT
,Rent DECIMAL(18, 2)
,RoomId INT
,CreatedDate Date
,StartDate Date
,EndDate Date
,VoidStartDate DATE
,VoidEndDate DATE
--,VoidLoss NVARCHAR(MAX)
)
insert into @demotest
select PropertyId,App_Id,Rent,RoomId,CreatedDate,StartDate,EndDate,EndDate+1 as VoidStartDate,
LEAD(StartDate) OVER (Partition BY PropertyId ORDER by Propertyid) As VoidEndDate
from tbl_AssignAppToProperty
SELECT ROW_NUMBER() OVER (
--ORDER BY A.Reference_id DESC
ORDER BY dt.PropertyId
) AS RowNumber
, app.Reference_ID as ApplicationRef
, A.Reference_ID as PropertyRefId
, A.ID as PropertyID
,vtp.TypeofProperty
,vPN.PropertyName AS PropertyName
,c.title AS Landlord
,P.FirstName
,P.LastName
,Ho.HouseholdLoginId AS HouseholdId
,vrt.RentType as RentFrequency
,dt.Rent
,A.Apptype
,A.FormId --added due to error
, A.session_guid
,CASE
WHEN
app.Reference_ID IS NULL Then A.DateOfSubmission
ELSE dt.VoidStartDate
END AS VoidStartDate
,Case
WHEN
dt.VoidEndDate is NULL Then getdate()
Else dt.VoidEndDate
END AS VoidEndDate
,datediff(ww,dt.VoidStartDate,dt.VoidEndDate) * dt.Rent AS VoidLoss
from tbl_Application A
INNER JOIN tbl_Form F ON F.id = A.FormId
left join @demotest dt on dt.PropertyId = A.ID
left join tbl_Application APP on dt.App_Id = APP.ID
Left JOIN tbl_household HO ON HO.Household_ID = APP.Household_Id
left JOIN v_TypeOfProperty vTP ON vTP.App_Id = A.ID
INNER JOIN v_PropertyName vPN ON A.ID = vPN.App_Id --record dropped from 78 to 57 to display only properties with name
--INNER JOIN tbl_ApplicationSubPortal ASS ON A.ID = ASS.AppID
INNER JOIN v_PropertyAddress vPA ON A.Session_Guid = vPA.MapGuid
LEFT JOIN tbl_applicationlandlord AL ON AL.AppId = A.id
LEFT JOIN tbl_choice c ON C.id = AL.LandlordId
--LEFT JOIN v_PropertyType vPT ON vPT.App_Id = A.ID
LEFT JOIN v_Person P ON P.AppId = dt.App_Id
AND P.HouseholdType = 'M'
LEFT JOIN v_RentType VRT on VRT.APP_ID = A.ID
where A.AppType='pro' --and A.Formid=803
AND F.PartnerId = @PartnerId
AND (
(@TAType = 0)
OR (vTP.TypeOfPropertyId = @TAType)
)
AND (
@PropertyRef IS NULL
OR A.Reference_ID LIKE '%' + @PropertyRef + '%'
)
AND (
@PropertyStatusId IS NULL
OR (A.App_status = @PropertyStatusId)
)
AND (
@PropertyId IS NULL
OR A.Reference_ID LIKE '%' + @PropertyId + '%'
)
AND (
@PropertyAddress IS NULL
OR ((isnull(vPA.FlatNo, '') + ' ' + isnull(vPA.BuildingName, '') + ' ' + isnull(vPA.StreetName, '') + ' ' + isnull(vPA.TownCity, '') + ' ' + isnull(vPA.County, '') + ' ' + isnull(vPA.PostCode, '')) LIKE '%' + @PropertyAddress + '%')
)
AND (
@HouseholdId IS NULL
OR HO.HouseholdLoginId LIKE '%' + @HouseholdId + '%'
)
AND (
@ReferenceID IS NULL
OR APP.Reference_ID LIKE '%' + @ReferenceID + '%'
)
AND (
(
CONVERT(DATE, @VoidStartDate, 103) IS NULL
OR CONVERT(DATE, @VoidEndDate, 103) IS NULL
)
OR (
(
CONVERT(DATE, dt.VoidStartDate, 103) BETWEEN CONVERT(DATE,@VoidStartDate, 103)
AND CONVERT(DATE, @VoidEndDate, 103)
)
AND (
CONVERT(DATE, dt.VoidEndDate, 103) BETWEEN CONVERT(DATE, @VoidStartDate, 103)
AND CONVERT(DATE, @VoidEndDate, 103)
)
)
)
END
This is my BindVoidData
method
public System.Data.DataSet BindVoidData(int partnerId, long userId, string taType, string Borough, string landlord, string propertyRef, string propertyType, string propertyAddress , string propertyStatus)
{
SqlCommand sqlCommand = new SqlCommand();
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
DataSet dataTable = new DataSet();
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["HousingRegister"].ConnectionString);
try
{
sqlCommand = new SqlCommand("sp_TADashboardVoid", connection);
sqlCommand.Parameters.Add(new SqlParameter("@PartnerId", partnerId));
sqlCommand.Parameters.Add(new SqlParameter("@UserId", userId));
sqlCommand.Parameters.Add(new SqlParameter("@TAType", taType));
sqlCommand.Parameters.Add(new SqlParameter("@Borough", Borough));
sqlCommand.Parameters.Add(new SqlParameter("@LandlordId", landlord));
sqlCommand.Parameters.Add(new SqlParameter("@PropertyId", propertyRef));
sqlCommand.Parameters.Add(new SqlParameter("@PropertyType", propertyType));
sqlCommand.Parameters.Add(new SqlParameter("@PropertyAddress", propertyAddress));
sqlCommand.Parameters.Add(new SqlParameter("@PropertyStatusId", propertyStatus));
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlDataAdapter.SelectCommand = sqlCommand;
sqlDataAdapter.Fill(dataTable);
}
catch (Exception ex)
{
throw ex;
}
finally
{
sqlCommand.Dispose();
connection.Close();
}
return dataTable;
}
The problem that I am facing is that the datatable is not returning me any rows due to which there are no records on Excel sheet, but when I tested the stored procedure using exec
on SQL Server, it is returning around 200 rows.
Can anyone please help me out on this as I am not sure how to proceed.