我的ASP.NET应用程序中有SqlDataSource
。该查询在SQL Server 2008 Management Studio中正常运行。
但是在ASP.NET应用程序中,它不返回任何值。
<asp:SqlDataSource ID="ChartOfAccountsFillerDS" runat="server"
ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
SelectCommand = "with cte as(select ChartOfAccountsID, Parent_ChartOfAccountsID, GL_Code, AccountName, 1 as [Level],
right('000' + cast(row_number()over(partition by Parent_ChartOfAccountsID order by GL_Code) as varchar(max)), 3) as [Path]
from ChartOfAccounts where Parent_ChartOfAccountsID is null
union all select t.ChartOfAccountsID, t.Parent_ChartOfAccountsID, t.GL_Code, t.AccountName, [Level] + 1,
[Path] + '.' + right('000' + cast(row_number()over(partition by t.Parent_ChartOfAccountsID order by t.GL_Code) as varchar(max)), 3)
from cte join ChartOfAccounts t on t.Parent_ChartOfAccountsID = cte.ChartOfAccountsID)
select ChartOfAccountsID as AccountID, Parent_ChartOfAccountsID as ParentID, GL_Code, (REPLICATE(CHAR(160), ([Level] -1)*5) + AccountName) AccountName, [Level], [Path] from cte order by [Path]">
</asp:SqlDataSource>