Sql Server で動作するクエリ。
Declare @from datetime, @to datetime, @status int, @SupervisorID uniqueidentifier
SELECT @to = '09-12-2012', @from = '02-02-2012', @status = 0, @SupervisorID = '2EB087F0-A419-4421-861A-6EBDFED9449A'
select nums.date as DayOff, [RequestID], [EmployeeName], [AbsenceType], [AbsenceBundle], [DateRequested], [FirstDay], [LastDay], [ReturnDay], [SupervisorName], [DaysHoursDesc] as DaysAbsent, [Description], Hours from
(select dateadd(day, number, @from) as date
from
(select distinct number from Numbers
) num
where dateadd(day, number, @from) < @to) nums right outer join [AbsenceRequests].[dbo].[AbsenceRequestWithDescriptions] a on (DateDiff(Day, a.FirstDay, nums.date) >= 0 and DateDiff(Day, a.LastDay, nums.date) <=0)
where
(([SupervisorID] = @SupervisorID) or ([EmployeeID] = @SupervisorID)
or
([SupervisorID] in (select SupervisorID from Viewers where [viewerID] = @SupervisorID)))
and((@status = StatusID) or (@status = '0'))
order by SupervisorName, EmployeeName, FirstDay, Hours
このクエリから得た結果
2012-06-06 00:00:00.000 515 apptest1 Vacation 55 - Vacation 2012-06-28 00:00:00.000 2012-06-06 00:00:00.000 2012-06-07 00:00:00.000 2012-06-08 00:00:00.000 apptest3 16 Hour(s) Pending 16
SqlDatasource 定義
<asp:SqlDataSource ID="EmployeeAbsenceRequestsSql" runat="server"
ConnectionString="<%$ ConnectionStrings:AbsenceRequestsConnectionString %>"
SelectCommand="
select nums.date as DayOff, [RequestID], [EmployeeName], [AbsenceType], [AbsenceBundle], [DateRequested], [FirstDay], [LastDay], [ReturnDay], [SupervisorName], [DaysHoursDesc] as DaysAbsent, [Description], Hours from
(select dateadd(day, number, @from) as date
from
(select distinct number from Numbers
) num
where dateadd(day, number, @from) < @to) nums right outer join [AbsenceRequests].[dbo].[AbsenceRequestWithDescriptions] a on (DateDiff(Day, a.FirstDay, nums.date) >= 0 and DateDiff(Day, a.LastDay, nums.date) <=0)
where
(([SupervisorID] = @SupervisorID) or ([EmployeeID] = @SupervisorID)
or
([SupervisorID] in (select SupervisorID from Viewers where [viewerID] = @SupervisorID)))
and ((@status = StatusID) or (@status = '0'))
order by SupervisorName, EmployeeName, FirstDay, Hours "
onselecting="EmployeeAbsenceRequestsSql_Selecting" >
<SelectParameters>
<asp:FormParameter DefaultValue=" " FormField="Fromtxt" Name="from" />
<asp:FormParameter DefaultValue=" " FormField="Totxt" Name="to" />
<asp:SessionParameter DefaultValue="""" Name="SupervisorID"
SessionField="EmployeeID" Type="Object" />
<asp:ControlParameter ControlID="Statusddl" DefaultValue="0" PropertyName="SelectedValue" Name="status" />
</SelectParameters>
</asp:SqlDataSource>
データソースのselectメソッドを呼び出すと、これで結果が得られますが、最初の列のDayOffは空白を返します(ウォッチを設定してDataViewをチェックすることでこれを確認しました)。以下は、選択クエリの結果を実行して読み取るために使用しているコードです。
protected void RefreshTreeview()
{
this.EmployeeAbsenceRequestsSql.SelectParameters["from"].DefaultValue = SafeDateString(this.Fromtxt.Text);
this.EmployeeAbsenceRequestsSql.SelectParameters["to"].DefaultValue = SafeDateString(this.Totxt.Text);
DataView dv = (DataView) this.EmployeeAbsenceRequestsSql.Select(new DataSourceSelectArguments());
FillTreeView(dv);
}
private void FillTreeView(DataView dv)
{
TreeNode CurrentSupervisorNode = null;
TreeNode CurrentEmployeeNode = null;
foreach (DataRow row in dv.Table.Rows)
{
String SupervisorName = SafeString(row["SupervisorName"]);
if ((CurrentSupervisorNode == null) || !CurrentSupervisorNode.Text.Equals(SupervisorName))
{
CurrentSupervisorNode = new TreeNode(SupervisorName);
this.AbsencesTV.Nodes.Add(CurrentSupervisorNode);
CurrentEmployeeNode = null;
}
String EmployeeName = SafeString(row["EmployeeName"]);
if (CurrentEmployeeNode == null || !CurrentEmployeeNode.Text.Equals(EmployeeName))
{
CurrentEmployeeNode = new TreeNode(EmployeeName);
CurrentSupervisorNode.ChildNodes.Add(CurrentEmployeeNode);
}
String DayOffSummary = SafeString(row["DayOff"]) + " " + SafeString(row["AbsenceBundle"]) +" " + SafeString(row["Description"]);
CurrentEmployeeNode.ChildNodes.Add(new TreeNode(DayOffSummary));
}
}
誰にもデバッグのアドバイスがありますか、それともなぜこれが起こっているのかに対するより良い答えがありますか?