Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ID	Name	   Designation	Level	        userid
15	Sh. B.M. Babbar	SDE-R2	00010104	       ELE15
16	Sh. Surinder  	AE-R2	0001010401	        ELE16
17	Sh. Roop Lal	JE-R2	000101040101	ELE17
18	Sh. Mansatinder	JE-R3	000101040102	ELE18
328	testnews	    JE_R2	000101040103	JE_R2
329	testnews	   JE_R2	000101040104	JE_R2
330	testnew12	   AE-R3	000101040105	AE-R3
331	testnews	   AE-R3    000101040106	AE-R3



This my employeeList table and above following table result showing sde(SDE-R2) as parent under AE as child and AE(AE-R2) under JE as subchild desiganation. i want to get only sde under AE Data through by level

i try this query "Select * from EmployeeList where level like '00010104%'" but showing all records

What I have tried:

i want to show only child data by parent data (SDE-R2 00010104)
"
16	Sh. Surinder  	AE-R2	0001010401	        ELE16
"
Posted
Updated 3-Dec-18 0:04am
v2
Comments
CHill60 3-Dec-18 4:42am    
Your data structure is not clear - how does "Level" indicate parent or child data?
Nishant.Chauhan80 3-Dec-18 5:00am    
level indicate hierarchy
sde parent
AE child
JE subchild

i want to show only child data through by parent level
CHill60 3-Dec-18 5:06am    
So include that in your where clause ... and Designation like 'AE%'
Jörgen Andersson 3-Dec-18 6:14am    
It's an enumerated path. Which is one of the three major ways to store hierarchical data. Same as MS is using in the hierarchyid
OriginalGriff 3-Dec-18 4:48am    
That makes no sense at all. Your query will - rightly - show all records becuas ethat is what you told it to do.
Exactly what you want it to show however is not at all clear - I have no idea what "level" is, where "AE Data" is stored, or what on earth the relationships are supposed to be.

Start by showing us exactly what output you want, and explain why the other rows are not to be included.

i want to show only child data by parent data (SDE-R2 00010104)

psuedo sql query is:
Select * from <<ChildTable>>
Inner join <<ParentTable>>
on <childtable.FKID>> = <<ParentTable.PKID>>
Where <<ParentTable.<<level>> like '00010104%'


I think it important to mention that you should never use Select * in a production query, as that can have negative implications for your data path in the future if something were to change with the structure of all the tables involved.

Select * is good for testing and for data dumps, but that is about it, IMHO.
 
Share this answer
 
v3
Since you only want the level below this query should do the job:
SQL
SELECT   *
FROM    EmployeeList
WHERE   LEVEL LIKE '00010104__'

But having a position based hierarchy key is something I'd recommend that you rethink.

And yes, never use SELECT * in production code.
 
Share this answer
 
I think solution 1 got the wrong end of the stick. Based on your comment you just need to add and AND clause to your query (and as pointed out by Slacker007, correct your column list). E.g.
SQL
Select ID, Name, Designation, Level, userid
from EmployeeList where level like '00010104%'
and Designation like 'AE%'
If you also want to include the "sub-child" designation you mention then add an OR clause but you will need to enclose it in brackets e.g.
SQL
Select ID, Name, Designation, Level, userid
from EmployeeList where level like '00010104%'
and ( Designation like 'AE%' or Designation like 'JE%' )
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900