Skip to content

Instantly share code, notes, and snippets.

@aliprogrammer69
Created August 7, 2016 12:15
Show Gist options
  • Select an option

  • Save aliprogrammer69/8fe281b6c2ddba3a3b4ee1dd6378036b to your computer and use it in GitHub Desktop.

Select an option

Save aliprogrammer69/8fe281b6c2ddba3a3b4ee1dd6378036b to your computer and use it in GitHub Desktop.
Select Xml As DataSet in sql server
DECLARE @xml XML='<root>
<row>
<CoreId>1</CoreId>
<Name>SrcName</Name>
<DataType>NVARCHAR(@LEN)</DataType>
<MaxLength>100</MaxLength>
<DefaultValue />
<IsNullable>0</IsNullable>
<Status>63</Status>
</row>
<row>
<CoreId>2</CoreId>
<Name>SrcField</Name>
<DataType>NVARCHAR(@LEN)</DataType>
<MaxLength>100</MaxLength>
<DefaultValue />
<IsNullable>0</IsNullable>
<Status>63</Status>
</row>
<row>
<CoreId>3</CoreId>
<Name>DestName</Name>
<DataType>NVARCHAR(@LEN)</DataType>
<MaxLength>100</MaxLength>
<DefaultValue />
<IsNullable>0</IsNullable>
<Status>63</Status>
</row>
<row>
<CoreId>4</CoreId>
<Name>SrcID</Name>
<DataType>BIGINT</DataType>
<DefaultValue />
<IsNullable>0</IsNullable>
<Status>63</Status>
</row>
<row>
<CoreId>5</CoreId>
<Name>DestID</Name>
<DataType>BIGINT</DataType>
<DefaultValue />
<IsNullable>0</IsNullable>
<Status>63</Status>
</row>
</root>'
SELECT
Tbl.Col.value('CoreId[1]', 'int') AS CoreId,
Tbl.Col.value('Name[1]', 'varchar(50)') AS Name,
Tbl.Col.value('DataType[1]', 'varchar(20)')AS DataType,
Tbl.Col.value('DefaultValue[1]', 'varchar(20)')AS DefaultValue,
Tbl.Col.value('IsNullable[1]', 'bit')AS IsNullable,
Tbl.Col.value('Status[1]', 'varchar(7)')AS Status
FROM @xml.nodes('/root/row') Tbl(Col)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment