Select within a select within a select within a select within a select -


i'm trying make heads & tails of reasoning behind multiple select statements within each other. in other words, point? note: i'm pretty familiar t-sql...i've been moved maintenance aspect of sql server developing side of it. below code (in part) confuses me:

select distinct id ,name ,typecode ,productid ,productname ,locationcode ,county ,state ,recommendationtype ,packagename ( select c.id     ,c.name     ,p.typecode     ,p.productid     ,p.productname     ,p.locationcode     ,p.county     ,p.state     ,'appened' recommendationtype     ,packagename (     select op.*         ,t.i.value('@productid', 'varchar(50)') productid         ,t.i.value('@name', 'varchar(50)') product     (         select pg.customerid             ,pg.name packagename             ,pg.runtimedefinition.query('/packagedefinition/products')                                    clist         product.package pg (nolock)         ) op     cross apply clist.nodes('products/task[@xsi:type="producttask"]') t(i)     ) m 

remember...this code in part.

thanks!!

well second 1 in seems tad pointless adds 1 column populated literal, other that.

in previous incarnation may have done more , re-factoring deemed effort, or maybe suffered developer amnesia. "i thought i'd done that" manager interruption, go off fix bit of code , forget haven't finished one.

as technique it's nice way of coming solution. call inside out, there's scientific name though.

after effort put in cross apply xml , getting working, it's easier use result , bolt on behaviour wrapping inner query.

it's less noisy temporary table , possibly developed pre ctes or dev not comfortable them .

try , write in oner, might start seeing point or two. :)


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -