CREATE TABLE #tab(col INT, x XML ); INSERT INTO #tab(col,...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

CREATE TABLE #tab(col INT, x XML );
    INSERT INTO #tab(col,x) VALUES (1,NULL), (2,NULL), (3,'<a>x</a>');
    
    SELECT 'Simple XML' AS description, name, system_type_name
    FROM sys.dm_exec_describe_first_result_set(
       N'SELECT col
         FROM #tab
         FOR XML AUTO', NULL, 0)  
    UNION ALL
    SELECT 'Wrapped with subquery', name, system_type_name
    FROM sys.dm_exec_describe_first_result_set(
       N'SELECT(SELECT col
                FROM #tab
                FOR XML AUTO) AS wrapped_subquery', NULL, 0)
    UNION ALL 
    SELECT 'XML column', name, system_type_name
    FROM sys.dm_exec_describe_first_result_set(
       N'SELECT x FROM #tab ', NULL, 0)
    UNION ALL
    SELECT 'Casted XML', name, system_type_name
    FROM sys.dm_exec_describe_first_result_set(
       N'SELECT CAST(''<o>O</o>'' AS XML) AS x', NULL, 0)
    UNION ALL
    SELECT 'Wrapped Casted XML', name, system_type_name
    FROM sys.dm_exec_describe_first_result_set(
       N'SELECT (SELECT CAST(''<o>O</o>'' AS XML) AS x) AS wrapped', NULL, 0)
    UNION ALL
    SELECT 'Text value', name, system_type_name
    FROM sys.dm_exec_describe_first_result_set(
    N'SELECT CAST(''aaa'' AS NTEXT) AS text_string', NULL, 0)
    UNION ALL
    SELECT 'Wrapped Text Value', name, system_type_name
    FROM sys.dm_exec_describe_first_result_set(
      N'SELECT (SELECT CAST(''aaa'' AS NTEXT)) AS text_string_wrapped', NULL, 0)

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results