Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
get first parent with a value
create table LOCATIONDETAIL (OID int primary key,NAME varchar(32), PARENTOID int); insert into LOCATIONDETAIL (OID,NAME,PARENTOID) VALUES (1,'HeadSite',0), (2,'Subsite1',1), (3,'subsite2',1), (4,'subsubsite1',2), (5,'subsubsite2',2), (6,'subsubsite3',3); create table RULESETCONFIG (rOID int primary key,LOCATIONDETAILOID int,VALUE int); INSERT INTO RULESETCONFIG (rOID,LOCATIONDETAILOID,VALUE) VALUES (1,1,30),(2,4,15); DECLARE @OID int; SET @OID=4 ;with LV as ( select OID ID,PARENTOID PID,NAME NAM, VALUE VAL FROM LOCATIONDETAIL left join RULESETCONFIG ON LOCATIONDETAILOID=OID ), gh as ( select ID gID,PID gPID,NAM gNAM,VAL gVAL from LV where ID=@OID union all select ID,PID,NAM,VAL FROM LV INNER JOIN gh ON gVAL is NULL AND gPID=ID) select * from gh WHERE gVAL>0
run
|
edit
|
history
|
help
0
New_1
M0413045.sql
sadasd
Practice
how can i mix both querys
hhzn
Uzd
Print 10 records
member
FIGURA5.2