こんにちは私はtblRegistration
3つのフィールドを持つテーブルを持っています
Member_ID(int) Left_Placement(Int) Right_Placement(int)
と1つの機能
CREATE FUNCTION [dbo].[fnGetChildCount](
@ParentId INT
)
RETURNS INT
BEGIN
DECLARE @ChildCount INT
DECLARE @Left INT
DECLARE @Right INT
SET @ChildCount = 0
IF NOT @ParentId IS NULL AND @ParentId <> 0
BEGIN
SET @ChildCount = 1
SELECT @Left = Left_Placement, @Right = Right_Placement FROM tblRegistration WHERE Member_ID = @ParentId
SELECT @ChildCount = @ChildCount + [dbo].[fnGetChildCount](@Left)
SELECT @ChildCount = @ChildCount + [dbo].[fnGetChildCount](@Right)
END
RETURN @ChildCount
END;
今、私はこのコードを使用しています
SqlCommand cmd = new SqlCommand("SELECT Member_ID, dbo.fnGetChildCount(Left_Placement) AS [Left Count], dbo.fnGetChildCount(Right_Placement) AS [Right Count] FROM tblRegistration", con);
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
string member = dr["dbo.fnGetChildCount(Left_Placement)"].ToString();
}
}
テーブル列ではない左カウントと右カウントを読み取るには、
どうすれば読むことができますかLEFT COUNT(dbo.fnGetChildCount(Left_Placement) AS [Left Count]) AND RIGHT COUNT(dbo.fnGetChildCount(Right_Placement) AS [Right Count])
前もって感謝します