Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SET @MyXml.modify('
- insert
- <myNode>
- {sql:variable("@MyVariable")}
- </myNode>
- into (/root[1]) ')
- DECLARE @NestedInput_SpecificDogNameId int
- SET @NestedInput_SpecificDogNameId = 99
- SELECT [dbo].[udfGetLowestLevelNestedNode_SpecificDogName]
- (@NestedInput_SpecificDogNameId)
- CREATE FUNCTION dbo.udfGetLowestLevelNestedNode_SpecificDogName
- (
- @NestedInput_SpecificDogNameId
- )
- RETURNS XML
- AS
- BEGIN
- -- Declare the return variable here
- DECLARE @ResultVar XML
- -- Add the T-SQL statements to compute the return value here
- SET @ResultVar =
- (
- SELECT
- @SpecificDogNameId as "@SpecificDogNameId",
- t.DogName
- FROM tblDogs t
- FOR XML PATH('Dog')
- )
- -- Return the result of the function
- RETURN @ResultVar
- END
- CREATE FUNCTION dbo.udfGetLowestLevelNestedNode_SpecificDogName
- (
- @NestedInput_SpecificDogNameId
- )
- RETURNS XML
- AS
- BEGIN
- -- Declare the return variable here
- DECLARE @ResultVar XML
- -- Add the T-SQL statements to compute the return value here
- SET @ResultVar =
- (
- SELECT
- @SpecificDogNameId as "@SpecificDogNameId",
- t.DogName
- FROM tblDogs t
- FOR XML PATH('Dog')
- )
- -- Return the result of the function
- RETURN @ResultVar
- END
- <Dog SpecificDogNameId=99>Astro</Dog>
- CREATE FUNCTION [dbo].[udfGetDogCollectionNode]()
- RETURNS XML
- AS
- BEGIN
- -- Declare the return variable here
- DECLARE @ResultVar XML
- -- Add the T-SQL statements to compute the return value here
- SET @ResultVar =
- (
- SELECT
- [dbo].[udfGetLowestLevelNestedNode_SpecificDogName]
- (t.SpecificDogNameId)
- FROM tblDogs t
- FOR XML PATH('DogCollection') ELEMENTS
- )
- -- Return the result of the function
- RETURN @ResultVar
- END
- SELECT [dbo].[udfGetDogCollectionNode]()
- <DogCollection>
- <Dog SpecificDogNameId="88">Dino</Dog>
- <Dog SpecificDogNameId="99">Astro</Dog>
- </DogCollection>
- CREATE FUNCTION [dbo].[udfGetAnimalCollectionNode]()
- RETURNS XML
- AS
- BEGIN
- DECLARE @ResultVar XML
- SET @ResultVar =
- (
- SELECT
- dbo.udfGetDogCollectionNode(),
- dbo.udfGetCatCollectionNode()
- FOR XML PATH('AnimalCollection'), ELEMENTS XSINIL
- )
- RETURN @ResultVar
- END
- SELECT [dbo].[udfGetAnimalCollectionNode]()
- <AnimalCollection>
- <DogCollection>
- <Dog SpecificDogNameId="88">Dino</Dog>
- <Dog SpecificDogNameId="99">Astro</Dog>
- </DogCollection>
- <CatCollection>
- <Cat SpecificCatNameId="11">Sylvester</Cat>
- <Cat SpecificCatNameId="22">Tom</Cat>
- <Cat SpecificCatNameId="33">Felix</Cat>
- </CatCollection>
- </AnimalCollection>
Add Comment
Please, Sign In to add comment