SQL HierarchyID,Didnt工作GetRoot [英] SQL HierarchyID , Didnt work GetRoot

查看:64
本文介绍了SQL HierarchyID,Didnt工作GetRoot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CREATE TABLE Offices
(
  NodeId                     hierarchyid PRIMARY KEY CLUSTERED,
  NodeLevel               AS NodeId.GetLevel(),
  OfficeId                    int UNIQUE NOT NULL,
  OfficeName              NVARCHAR(50) NOT NULL,
  QuarterlySales          DECIMAL(15,2) NOT NULL
)
GO

INSERT INTO Offices
( NodeId, OfficeId, OfficeName, QuarterlySales)
VALUES
(hierarchyid :: GetRoot(), 1, 'Head Office', 0);
GO

SELECT *,NodeId.ToString() FROM Offices





NodeID在NodeID栏目中为空白

为什么?请帮忙!



SQl版本= Microsoft SQL Server 2012 - 11.0.5058.0(X64)

2014年5月14日18:34:29

版权所有(c)Microsoft Corporation

Windows NT 6.3企业版(64位)< X64> (Build 9600:)



NodeID is Blank in Column "NodeID"
Why ? Please help !

SQl Version = Microsoft SQL Server 2012 - 11.0.5058.0 (X64)
May 14 2014 18:34:29
Copyright (c) Microsoft Corporation
Enterprise Edition (64-bit) on Windows NT 6.3 <X64> (Build 9600: )

推荐答案

在测试代码时,记录的nodeid为0x,而不是空白。所以数据看起来像

When tested the code the nodeid for the record is 0x, not blank. So the data looks like
NodeId NodeLevel OfficeId OfficeName  QuarterlySales (No column name)
------ --------- -------- ----------  -------------- ----------------
0x     0         1        Head Office 0.00           /



如果你的意思是ToString方法没有返回数字,这对于root来说是正确的。层次结构中的下一个项目将具有序数和更深层结构,如 ToString 中所述[ ^ ]


这篇关于SQL HierarchyID,Didnt工作GetRoot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆