Quantcast
Channel: ฟอรัม Getting started with SQL Server
Viewing all articles
Browse latest Browse all 8428

Parent Child dispaly

$
0
0
With my new data, need result for below scenario
´`````````````
CREATE TABLE
´´´´´´´´´´´´´´´´

CREATE TABLE [dbo].[Travel_Master](	
	[Load_Id] [int] NULL,
	[Mode_Id] [nchar](2) NULL,
	[Mode_Info] [nchar](10) NULL,
	[Has_Nodes] [nchar](3) NULL
) ON [PRIMARY]	
	
CREATE TABLE [dbo].[Travel_Quantity](	
	[Load_Id] [int] NULL,
	[Mode_Sno] [int] NULL,
	[Mode_Id] [nchar](2) NULL,
	[Mode_Parent_Sno] [int] NULL,
	[QA] [numeric](18, 0) NULL
) ON [PRIMARY]	

===============================
Insert DATA TABLE 1
===============================
 
INSERT INTO [dbo].[Travel_Master] ([Load_Id] ,[Mode_Id] ,[Mode_Info] ,[Has_Nodes]) VALUES ( 1,'AP' ,'AIR' ,'Yes')
INSERT INTO [dbo].[Travel_Master] ([Load_Id] ,[Mode_Id] ,[Mode_Info] ,[Has_Nodes]) VALUES ( 1,'FL' ,'FLIGHT' ,'Yes')
INSERT INTO [dbo].[Travel_Master] ([Load_Id] ,[Mode_Id] ,[Mode_Info] ,[Has_Nodes]) VALUES ( 1,'FP' ,'FLIGHT-Passenger' ,'No')
INSERT INTO [dbo].[Travel_Master] ([Load_Id] ,[Mode_Id] ,[Mode_Info] ,[Has_Nodes]) VALUES ( 1,'SE' ,'SEA' ,'Yes')
INSERT INTO [dbo].[Travel_Master] ([Load_Id] ,[Mode_Id] ,[Mode_Info] ,[Has_Nodes]) VALUES ( 1,'SP' ,'SHIP' ,'No')
INSERT INTO [dbo].[Travel_Master] ([Load_Id] ,[Mode_Id] ,[Mode_Info] ,[Has_Nodes]) VALUES ( 1,'RD' ,'ROAD' ,'No')
INSERT INTO [dbo].[Travel_Master] ([Load_Id] ,[Mode_Id] ,[Mode_Info] ,[Has_Nodes]) VALUES ( 1,'BU' ,'BUS' ,'No')



===============================
Insert DATA TABLE 2
===============================
 INSERT INTO [Travel_Quantity]([Load_Id],[Mode_Sno],[Mode_Id],[Mode_Parent_Sno],[QA]) VALUES  ( 1,'1' ,'AP' ,'-1','4' )	
 INSERT INTO [Travel_Quantity]([Load_Id],[Mode_Sno],[Mode_Id],[Mode_Parent_Sno],[QA]) VALUES  ( 1,'2' ,'FL' ,'1','2' )	
 INSERT INTO [Travel_Quantity]([Load_Id],[Mode_Sno],[Mode_Id],[Mode_Parent_Sno],[QA]) VALUES  ( 1,'3' ,'FP' ,'2','1' )	
 INSERT INTO [Travel_Quantity]([Load_Id],[Mode_Sno],[Mode_Id],[Mode_Parent_Sno],[QA]) VALUES  ( 1,'4' ,'SE' ,'-1','0' )	
 INSERT INTO [Travel_Quantity]([Load_Id],[Mode_Sno],[Mode_Id],[Mode_Parent_Sno],[QA]) VALUES  ( 1,'5' ,'SP' ,'4','1' )	
 INSERT INTO [Travel_Quantity]([Load_Id],[Mode_Sno],[Mode_Id],[Mode_Parent_Sno],[QA]) VALUES  ( 1,'6' ,'RD' ,'-1','6' )	
 INSERT INTO [Travel_Quantity]([Load_Id],[Mode_Sno],[Mode_Id],[Mode_Parent_Sno],[QA]) VALUES  ( 1,'7' ,'BU' ,'6','3' )	


========
RULE
========

1.QA of Parent Row value Greater than 0-  Consider Parent and 1st Node.
From the avaliable result,

2.HasNodes = Yes, Display Parent and 1st Node
3.HasNodes = No, Display Parent Only.

================
Expected Result		
================
Mode_Info	|Mode_Detail	|QA
AIR	|	|4
AIR	|FLIGHT	|2
ROAD	|	|6


ShanmugaRaj


Viewing all articles
Browse latest Browse all 8428

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>