私のSQLプロシージャは完全に機能しています。しかし、クラスから呼び出すと、データが返されません。そして、私はこのエラーを受け取ります。Column 'Territory_Name' does not belong to table .
コードをデバッグしたところ、すべてのパラメーターが正しく渡されていることがわかりましたが、プロシージャーはデータを返しません。誰かがアイデアを持っているなら、私を助けてください。
私のストアドプロシージャは次のとおりです。
ALTER PROCEDURE dbo.SPFilterCRMRequests
(
/* for Time Span */
@WeekList varchar(50) = null,
@MonthList varchar(50) = null,
@YearList varchar(50) = null,
@QuaterList varchar(50) = null,
/* for other specific criteria */
@PriorityList varchar(50) = null,
@Division_IdList varchar(50) = null,
@CRM_Service_Type_IdList varchar(50) = null,
@CRM_Notation_IdList varchar(50) = null,
@CRM_State_IdList varchar(50) = null,
@Service_State_IdList varchar(50) = null,
@Estimated_Amount float
/* for Designation
@Requester varchar(20),
@Suggester varchar(20) */
)
AS
SET NOCOUNT ON
/*Declare @date3 DateTime = CONVERT(date,'2/8/2013 5:17:00 PM')*/
DECLARE @sql nvarchar(4000)
SELECT @sql='SELECT
CRMDR.Id as Id,
LEFT(GEOTREE.GEONAME,15) as Territory_Name,
CRMDR.Request_For_Id as Request_For_Id,
DRMST.DRNAME as Request_For_Name,
USERSTBM.USERNAME as Requester_Name,
Division.Div_Name as Division_Name,
USERSABM.USERNAME as Suggester_Name,
CRMDR.Estimated_Amount as Estimated_Amount,
CRMDR.Actual_Amount as Actual_Amount,
CRMDR.Compute_Priority as Compute_Priority,
CRMNotation.Notation_Name as CRM_Notation_Name,
CRMServiceType.ServiceName as CRM_Service_Type_Name,
CRMDR.Deadline as Deadline,
CRMDR.Executed_Date as Executed_Date,
CRMDR.Date_Created as Date_Created,
CRMDR.Compute_CRM_State as Compute_CRM_State,
CRMDR.Compute_Service_State as Compute_Service_State
From [CRM].[dbo].[CRM_Doctor_Request] AS CRMDR
JOIN [ASES].[dbo].[USERS] AS USERSTBM
ON CRMDR.Requester COLLATE SQL_Latin1_General_CP1_CI_AS = USERSTBM.RID COLLATE SQL_Latin1_General_CP1_CI_AS
JOIN [ASES].[dbo].[USERS] AS USERSABM
ON CRMDR.Suggester COLLATE SQL_Latin1_General_CP1_CI_AS = USERSABM.RID COLLATE SQL_Latin1_General_CP1_CI_AS
JOIN [ASES].[dbo].[GEOTREE] AS GEOTREE
ON CRMDR.Territory COLLATE SQL_Latin1_General_CP1_CI_AS = GEOTREE.RID COLLATE SQL_Latin1_General_CP1_CI_AS
JOIN [ASES].[dbo].[DRMST] AS DRMST
ON CRMDR.Request_For_Id COLLATE SQL_Latin1_General_CP1_CI_AS = DRMST.MDLNO COLLATE SQL_Latin1_General_CP1_CI_AS
JOIN [CRM].[dbo].[CRM_Request_For_Type] AS CRMReqForType
ON CRMDR.CRM_Request_For_Type_Id = CRMReqForType.Id
JOIN [CRM].[dbo].[CRM_Notation] AS CRMNotation
ON CRMDR.CRM_Notation_Id = CRMNotation.Id
JOIN [CRM].[dbo].[CRM_Service_Type] AS CRMServiceType
ON CRMDR.CRM_Service_Type_Id = CRMServiceType.Id
JOIN [CRM].[dbo].[Division] AS Division
ON CRMDR.Division_Id = Division.Id
WHERE CRMDR.Is_Deleted=0 '
If (@MonthList) IS NOT NULL
SELECT @sql=@sql + ' AND MONTH(CRMDR.Date_Created) in (' + @MonthList + ') '
If (@YearList) IS NOT NULL
SELECT @sql=@sql + ' AND (CRMDR.Date_Created) in (' + @YearList + ') '
If (@WeekList) IS NOT NULL
BEGIN
DECLARE @DateCondition varchar(1000)
DECLARE @ColumnName varchar(50) = 'CRMDR.Date_Created'
-- pass the columnname on which condition needs to be aaplied
EXEC dbo.SPWhereconditionForMultipleWeeks @WeekList, @ColumnName, @DateCondition OUTPUT
SELECT @DateCondition
-- if (LEN(@DateCondition) > 0 )
SELECT @sql=@sql + ' AND '+ SUBSTRING(@DateCondition, 1, LEN(@DateCondition)-3)
END
If (@QuaterList) IS NOT NULL
BEGIN
DECLARE @MonthsList varchar(1000)
EXEC dbo.SPGetMonthsListforMultipleQuaters @QuaterList, @MonthsList OUTPUT
SELECT @MonthsList
-- print @MonthsList
-- if (LEN(@MonthsList) > 0 )
SELECT @sql=@sql + ' AND MONTH(CRMDR.Date_Created) in ('
+ SUBSTRING(@MonthsList, 1, LEN(@MonthsList)-1) +')'
END
If (@PriorityList) IS NOT NULL
SELECT @sql=@sql + ' AND Priority in (' + @PriorityList + ') '
If (@Division_IdList) IS NOT NULL
SELECT @sql=@sql + ' AND Division_Id in (' + @Division_IdList + ') '
If (@CRM_Service_Type_IdList) IS NOT NULL
SELECT @sql=@sql + ' AND CRM_Service_Type_Id in (' + @CRM_Service_Type_IdList + ') '
If (@CRM_Notation_IdList) IS NOT NULL
SELECT @sql=@sql + ' AND CRM_Notation_Id in (' + @CRM_Notation_IdList + ') '
If (@Estimated_Amount) IS NOT NULL
SELECT @sql=@sql + ' AND Estimated_Amount > (@Estimated_Amount) '
If (@CRM_State_IdList) IS NOT NULL
SELECT @sql=@sql + ' AND CRM_State_Id in (' + @CRM_State_IdList + ') '
If (@Service_State_IdList) IS NOT NULL
SELECT @sql=@sql + ' AND Service_State_Id in (' + @Service_State_IdList + ') '
SELECT @sql=@sql + ' ORDER BY CRMDR.Id DESC '
--print @sql
EXEC sp_executesql @sql, N' @MonthList varchar(50),
@YearList varchar(50),
@QuaterList varchar(50),
@PriorityList varchar(50),
@Division_IdList varchar(50),
@CRM_Service_Type_IdList varchar(50),
@CRM_Notation_IdList varchar(50),
@Estimated_Amount float,
@CRM_State_IdList varchar(50),
@Service_State_IdList varchar(50) ',
@MonthList,
@YearList,
@QuaterList,
@PriorityList,
@Division_IdList,
@CRM_Service_Type_IdList,
@CRM_Notation_IdList,
@Estimated_Amount,
@CRM_State_IdList,
@Service_State_IdList
RETURN
プロシージャを呼び出す私のクラス:
public static List<CRM_Doctor_Request> FilterCRM_Doctor_Request_Details(string WeekList, string MonthList, string YearList, string QuaterList, string PriorityList, string Division_IdList, string CRM_Service_Type_IdList, string CRM_Notation_IdList, string CRM_State_IdList, string Service_State_IdList, float Estimated_Amount)
{
string proc = "SPFilterCRMRequests";
List<SqlParameter> arrParam = new List<SqlParameter>();
SqlParameter pWeekList = new SqlParameter("@WeekList", SqlDbType.VarChar);
SqlParameter pMonthList = new SqlParameter("@MonthList", SqlDbType.VarChar);
SqlParameter pYearList = new SqlParameter("@YearList", SqlDbType.VarChar);
SqlParameter pQuaterList = new SqlParameter("@QuaterList", SqlDbType.VarChar);
SqlParameter pPriorityList = new SqlParameter("@PriorityList", SqlDbType.VarChar);
SqlParameter pDivision_IdList = new SqlParameter("@Division_IdList", SqlDbType.VarChar);
SqlParameter pCRM_Service_Type_IdList = new SqlParameter("@CRM_Service_Type_IdList", SqlDbType.VarChar);
SqlParameter pCRM_Notation_IdList = new SqlParameter("@CRM_Notation_IdList", SqlDbType.VarChar);
SqlParameter pCRM_State_IdList = new SqlParameter("@CRM_State_IdList", SqlDbType.VarChar);
SqlParameter pService_State_IdList = new SqlParameter("@Service_State_IdList", SqlDbType.VarChar);
SqlParameter pEstimated_Amount = new SqlParameter("@Estimated_Amount", SqlDbType.Float);
pWeekList.Value = WeekList;
pMonthList.Value = MonthList;
pYearList.Value = YearList;
pQuaterList.Value = QuaterList;
pPriorityList.Value = PriorityList;
pDivision_IdList.Value = Division_IdList;
pCRM_Service_Type_IdList.Value = CRM_Service_Type_IdList;
pCRM_Notation_IdList.Value = CRM_Notation_IdList;
pCRM_State_IdList.Value = CRM_State_IdList;
pService_State_IdList.Value = Service_State_IdList;
pEstimated_Amount.Value = Estimated_Amount;
arrParam.Add(pWeekList);
arrParam.Add(pMonthList);
arrParam.Add(pYearList);
arrParam.Add(pQuaterList);
arrParam.Add(pPriorityList);
arrParam.Add(pDivision_IdList);
arrParam.Add(pCRM_Service_Type_IdList);
arrParam.Add(pCRM_Notation_IdList);
arrParam.Add(pCRM_State_IdList);
arrParam.Add(pService_State_IdList);
arrParam.Add(pEstimated_Amount);
DataTable table = DataProvider.SelectStoreProcedure(proc, arrParam);
List<CRM_Doctor_Request> ListCRM_Doctor_Request = new List<CRM_Doctor_Request>();
foreach (DataRow row in table.Rows)
{
CRM_Doctor_Request CRM_Doctor_RequestObj = new CRM_Doctor_Request();
CRM_Doctor_RequestObj.Territory_Name = Convert.ToString(row["Territory_Name"]);
CRM_Doctor_RequestObj.Request_For_Id = Convert.ToString(row["Request_For_Id"]);
CRM_Doctor_RequestObj.Request_For_Name = Convert.ToString(row["Request_For_Name"]);
CRM_Doctor_RequestObj.Requester_Name = Convert.ToString(row["Requester_Name"]);
CRM_Doctor_RequestObj.Division_Name = Convert.ToString(row["Division_Name"]);
CRM_Doctor_RequestObj.Suggester_Name = Convert.ToString(row["Suggester_Name"]);
CRM_Doctor_RequestObj.Id = Convert.ToInt32(row["Id"]);
CRM_Doctor_RequestObj.Compute_Priority = Convert.ToString(row["Compute_Priority"]);
CRM_Doctor_RequestObj.CRM_Notation_Name = Convert.ToString(row["CRM_Notation_Name"]);
CRM_Doctor_RequestObj.CRM_Service_Type_Name = Convert.ToString(row["CRM_Service_Type_Name"]);
CRM_Doctor_RequestObj.Compute_CRM_State = Convert.ToString(row["Compute_CRM_State"]);
CRM_Doctor_RequestObj.Compute_Service_State = Convert.ToString(row["Compute_Service_State"]);
ListCRM_Doctor_Request.Add(CRM_Doctor_RequestObj);
}
return ListCRM_Doctor_Request;
}
DataProvider.SelectStoreProcedure のコード:
class DataProvider
{
public static string connectionString = ConfigurationManager.ConnectionStrings["connect_str"].ConnectionString;
public static DataTable SelectStoreProcedure(string ProcName, List<SqlParameter> ParaArr)
{
DataTable data = new DataTable();
SqlConnection cn = new SqlConnection(connectionString);
cn.Open();
SqlCommand cmd = new SqlCommand(ProcName, cn);
foreach (SqlParameter para in ParaArr)
{
cmd.Parameters.Add(para);
}
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(data);
cn.Close();
return data;
}
}