Thanks for the with xmlnamespace! I am trying to get procs and their
physicalops to see which ones need tuning ie have index scan etc.
#queryplan is created in the previous post.
if object_id('tempdb.dbo.#xmlshred') is not null
drop table #xmlshred
if object_id('tempdb.dbo.#report') is not null
drop table #report
create table #xmlshred (PhysicalOp varchar(100), LogicalOp varchar(100),
EstimateCPU decimal(18,3), EstimateIO decimal(18,3),
EstimatedTotalSubtreeCost decimal(18,3), AvgRowSize int)
create table #report (ProcName sysname, PhysicalOp varchar(100), LogicalOp
varchar(100), EstimateCPU decimal(18,3), EstimateIO decimal(18,3),
EstimatedTotalSubtreeCost decimal(18,3), AvgRowSize int)
declare @plan xml
declare @pName sysname
declare curNodes cursor for select objectname, query_plan from #queryplan
where query_plan is not null
open curNodes
fetch curNodes into @pName, @plan
while @@fetch_status <> -1
begin
WITH XMLNAMESPACES(DEFAULT
'http://schemas.microsoft.com/sqlserver/2004/07/showplan')
insert #xmlshred select ro.RelOp.value('@PhysicalOp', 'varchar(100)')
PhysicalOp
, ro.RelOp.value('@LogicalOp', 'varchar(100)') LogicalOp
, convert(decimal(18,6),CAST (CAST
(ro.RelOp.value('@EstimateCPU', 'varchar(100)') AS float(24)) AS
decimal(18, 13))) EstimateCPU
, convert(decimal(18,6),CAST (CAST
(ro.RelOp.value('@EstimateIO', 'varchar(100)') AS float(24)) AS decimal(18,
13))) EstimateIO
, convert(decimal(18,6),CAST (CAST
(ro.RelOp.value('@EstimatedTotalSubtreeCost', 'varchar(100)') AS float(24))
AS decimal(18, 13))) EstimatedTotalSubtreeCost
, convert(decimal(18,6),CAST (CAST
(ro.RelOp.value('@AvgRowSize', 'varchar(100)') AS int) AS int)) AvgRowSize
FROM @plan.nodes('//RelOp') as ro(RelOp)
insert #report select @pName, PhysicalOp, LogicalOp, EstimateCPU,
EstimateIO, EstimatedTotalSubtreeCost, AvgRowSize from #xmlshred
fetch curNodes into @pName, @plan
end
close curNodes
deallocate curNodes
select * from #report
> Not sure what you mean here, but is this what you're after?
>
[quoted text clipped - 34 lines]
>> This si the query
>> http://groups.google.com/group/microsoft.public.sqlserver.programming/browse_thr
ead/thread/880f7ff6483fa50f/e76ef170b02e555e?lnk=st&q=%40plan.nodes+relop#e76ef1
70b02e555e