Click here to Skip to main content
15,895,462 members

Comments by Abuamer (Top 22 by date)

Abuamer 9-Jan-22 14:04pm View    
MR Dave Kreskowiak:
It is not appropriate to make fun of me. If you don't have an answer, don't make fun of anyone.
Abuamer 26-Nov-21 5:56am View    
No it works fine
Abuamer 26-Nov-21 5:56am View    
No it works fine
Abuamer 25-Nov-21 15:40pm View    
please more explain
Abuamer 29-Dec-19 3:31am View    
OK I will Give You An Example For What I want In More Details. Cristiano Ronaldo Is Agreat Player And His Full Name Is (Cristaino Ronaldo Dos Santos Aveiro).
Aveiro Is the grand Grand Father with level 0.
Dos Santos is the son Of Aveiro with level 1.
Ronaldo Is the son of Dos Santos with level 2.
And Finally Cristiano Is The Son of Ronaldo With Level 3.

what i want to do is when i select cristiano my output should be like that
(Cristiano / Ronaldo / Dos Santos / Aveiro)
the output should gives me Cristiano / his father /his grand Father/his grand grand Father)

and this is the query to create the table with hierarchical view

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Tbl_ChartOfAccountsTree](
[Chart_ID] [int] NOT NULL,
[Chart_Name] [nvarchar](500) NULL,
[Account_Level] [int] NULL,
[ParentAccount] [int] NULL,
[Accoutn_Type] [nvarchar](150) NULL,
[Direction] [nvarchar](150) NULL,
[OB] [decimal](18, 2) NULL,
[Date] [date] NULL,
CONSTRAINT [PK_Tbl_ChartOfAccountsTree] PRIMARY KEY CLUSTERED
(
[Chart_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
INSERT [dbo].[Tbl_ChartOfAccountsTree] ([Chart_ID], [Chart_Name], [Account_Level], [ParentAccount], [Accoutn_Type], [Direction], [OB], [Date]) VALUES (0, N'Aveiro', 0, NULL, N'Parent', NULL, CAST(0.00 AS Decimal(18, 2)), CAST(N'2019-07-01' AS Date))
GO
INSERT [dbo].[Tbl_ChartOfAccountsTree] ([Chart_ID], [Chart_Name], [Account_Level], [ParentAccount], [Accoutn_Type], [Direction], [OB], [Date]) VALUES (1000, N'Dos Santos', 1, 0, N'Parent', N'Balance', CAST(0.00 AS Decimal(18, 2)), CAST(N'2019-07-01' AS Date))
GO
INSERT [dbo].[Tbl_ChartOfAccountsTree] ([Chart_ID], [Chart_Name], [Account_Level], [ParentAccount], [Accoutn_Type], [Direction], [OB], [Date]) VALUES (1100, N'Ronaldo', 2, 1000, N'Parent', N'Balance', CAST(0.00 AS Decimal(18, 2)), CAST(N'2019-07-01' AS Date))
GO
INSERT [dbo].[Tbl_ChartOfAccountsTree] ([Chart_ID], [Chart_Name], [Account_Level], [ParentAccount], [Accoutn_Type], [Direction], [OB], [Date]) VALUES (1101, N'Cristiano', 3, 1100, N'Child', N'Balance', CAST(0.00 AS Decimal(18, 2)), CAST(N'2019-11-01' AS Date))
GO
ALTER TABLE [dbo].[Tbl_ChartOfAccountsTree] WITH CHECK ADD CONSTRAINT [FK_Tbl_ChartOfAccountsTree_Tbl_ChartOfAccountsTree] FOREIGN KEY([ParentAccount])
REFERENCES [dbo].[Tbl_ChartOfAccountsTree] ([Chart_ID])
GO
ALTER TABLE [dbo].[Tbl_ChartOfAccountsTree] CHECK CONSTRAINT [FK_Tbl_ChartOfAccountsTree_Tbl_ChartOfAccountsTree]
GO
so please is there is any possible help