Erland - I just did a quick test. The differences weren't as bad as the subtree estimates would have indicated but they weren't exactly close either. The typed version (on average) took just over twice as long to execute.
Test conditions were as follows:
AdventureWorks2012 database
On average, the non-typed version executed in ~190 ms and the typed version executes in ~405 ms.
Test bed was the following:
@@VERSION =
Microsoft SQL Server 2012 - 11.0.2218.0 (X64)
Jun 12 2012 13:05:25
Copyright (c) Microsoft Corporation
Developer Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: )
Hardware =
Processor: Core i7-4770K @ 3.50GHz (4 physical cores / 8 logical cores)
Ram: 16.0 GB @ 2400 MHz
HD: SSD
Here are the two test scripts that I used... (each run in it own SSMS tab)
-- Typed version --
DECLARE @BegDT DATETIME2(7) = SYSDATETIME()
SELECT
sod1.SalesOrderID,
STUFF((
SELECT ', ' + CAST(sod2.ProductID AS VARCHAR(8))
FROM Sales.SalesOrderDetail sod2
WHERE sod1.SalesOrderID = sod2.SalesOrderID
FOR XML PATH(''), TYPE).value('.', 'varchar(max)'), 1, 2, '') AS csv
FROM
Sales.SalesOrderDetail sod1
GROUP BY
sod1.SalesOrderID
SELECT DATEDIFF(ms, @BegDT, SYSDATETIME()) AS ExecTimeMS
-- Non-typed version --
DECLARE @BegDT DATETIME2(7) = SYSDATETIME()
SELECT
sod1.SalesOrderID,
STUFF((
SELECT ', ' + CAST(sod2.ProductID AS VARCHAR(8))
FROM Sales.SalesOrderDetail sod2
WHERE sod1.SalesOrderID = sod2.SalesOrderID
FOR XML PATH('')), 1, 2, '') AS csv
FROM
Sales.SalesOrderDetail sod1
GROUP BY
sod1.SalesOrderID
SELECT DATEDIFF(ms, @BegDT, SYSDATETIME()) AS ExecTimeMS
If you see holes in my test approach, please let me know.
Thanks,
Jason