ÎÒÃÇÔÚƽ³£µÄϵͳ¿ª·¢Öг£³£»áÓöµ½ÏñÎÞÏÞ¼¶·ÖÀàÕâÑùµÄÊ÷ÐͽṹÊý¾Ý£¬ÏÖÌṩһ¸ö¿ÉÓõÄÊý¾Ý¿â´æ´¢¹ý³Ì£¬¿ÉÒÔÍê³ÉÊ÷ÐͽṹÊý¾ÝµÄÅÅÐò¡£
»·¾³£ºwindows7+Sql Server 2008
˵Ã÷£ºÏÂÃæ´úÂëÒѾת»»³ÉSql server2000µÄ½Å±¾£¬´¦ÀíЧ¹ûÈçÏ£¬¿´sortname×ֶνá¹û,´úÂë¾¹ý²âÊÔ¡£
´´½¨Ê÷Ðͱí
CREATE TABLE [dbo].[categories](
[category_id] [int] IDENTITY(1,1) NOT NULL,
[parent_id] [int] NULL,
[category_name] [varchar](500) NULL,
CONSTRAINT [PK_categories] PRIMARY KEY CLUSTERED
(
[category_id] ASC
) ON [PRIMARY]
) ON [PRIMARY]
GO
²åÈë²âÊÔÊý¾Ý
INSERT [dbo].[categories] ([category_id], [parent_id], [category_name]) VALUES (1, 0, CONVERT(TEXT, N'A'))
INSERT [dbo].[categories] ([category_id], [parent_id], [category_name]) VALUES (2, 0, CONVERT(TEXT, N'B'))
INSERT [dbo].[categories] ([category_id], [parent_id], [category_name]) VALUES (3, 1, CONVERT(TEXT, N'AA'))
INSERT [dbo].[categories] ([category_id], [parent_id], [category_name]) VALUES (4, 3, CONVERT(TEXT, N'AAA'))
INSERT [dbo].[categories] ([category_id], [parent_id], [category_name]) VALUES (5, 2, CONVERT(TEXT, N'BB'))
INSERT [dbo].[categories] ([category_id], [parent_id], [category_name]) VALUES (6, 1, CONVERT(TEXT, N'AA2'))
INSERT [dbo].[categories] ([category_id], [parent_id], [category_name]) VALUES (7, 1, CONVERT(TEXT, N'AA3'))
INSERT [dbo].[categories] ([category_id], [parent_id], [category_name]) VALUES (8, 3, CONVERT(TEXT, N'AAA2'))
INSERT [dbo].[categories] ([category_id], [parent_id], [category_name]) VALUES (9, 4, CONVERT(TEXT, N'AAA3'))
INSERT [dbo].[categories] ([category_id], [parent_id], [category_name]) VALUES (10, 2, CONVERT(TEXT, N'BB2'))
´´½¨´æ´¢¹ý³Ì£¬±íÖеÄlevelΪ¼¶±ðÉî¶È£¬Í¨¹ýÉú³ÉµÄÁÙʱ±íÓë·ÖÀà±í¹ØÁªÏÔʾ½á¹û¡£
CREATE PROCEDURE [dbo].[Get_TreeData]
AS
BEGIN
--´´½¨ÁÙʱ±í
create table #tmp_table (id int,[level] int)
declare @LevelValue int
set @LevelValue=0
insert #tmp_table select 0,@LevelValue
--½«Êý¾ÝдÈëµ½ÁÙʱ±í
while @@rowcount>0
begin
set @LevelValue=@LevelValue+1
SQLSERVER 2005²ÉÓÃ'SQLSERVERÉí·ÝÑéÖ¤'È¥µÇ¼, ³ö´íµÄÔÒòÊÇ:'Óû§ 'sa' µÇ¼ʧ°Ü¡£¸ÃÓû§Óë¿ÉÐÅ SQL Server Á¬½ÓÎÞ¹ØÁª'.½ñÌìÉÏÍøÉϲéÁË°ëÌì²Å¸ã¶¨µÄ¡£
¾ßÌåµÄ·½·¨ÊÇ£º ¡¡¡¡
1£º´ò¿ªSQL Server Manager¹ÜÀíÆ÷£¡ÔÚ×óÃæÕÒµ½ ‘°²È«ÐÔ’ µ¥»÷ÓÒ¼ü Ñ¡Ôñ‘н¨”£¬“µÇ¼” µ¯³öÒ»¸ö¶Ô»°¿ò£¬Ô ......
½ñÌìÓöµ½¸öÓÐÒâ˼µÄÎÊÌ⣬ÊÇÒ»¸ö·Ö×éÅÅÐòµÄÎÊÌ⣬²»¹ýÒªÇó·Ö×éºÍ·Ö×é¼äÒ²ÒªÅÅÐò£¬Èç¹ûÕâ¸ö×éÄÚÓÐÒ»ÌõÊý¾ÝÊÇ×î½ü¸üеģ¬ÄÇôÕâÕû¸ö×鶼Ӧ¸ÃÅÅÔÚÇ°Ãæ¡£
ÏÂÃæÒÔOracleµÄHRʾÀýSchemaÖеÄemployees±íΪÀý£º
Óï¾ä°´²¿ÃÅ·Ö×飬·Ö×éÖ®¼äµÄÅÅÐòÊÇÕâÑùµÄ£ºÈç¹ûÕû¸ö·Ö×éÖÐÓÐÒ»¸öÔ±¹¤µÄhire_dateÊÇ×îеģ¬ÄÇôÕâ¸ö·Ö×é¾ÍÓ¦¸ÃÅÅÔÚÆä ......