Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
get first parent with a value
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
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
View schema
Execution time: 0,02 sec, rows selected: 2, rows affected: 8, absolute service time: 0,17 sec
edit mode
|
history
|
discussion
gID
gPID
gNAM
gVAL
1
4
2
subsubsite1
15