
-- declare a variable of XML data type
DECLARE @x XML
-- cast a string to it (must be a valid XML document or fragment)
SET @x = CAST('<doc1><name>Bob</name></doc1>' AS XML)
-- use it
INSERT xml_tab VALUES(@x)
GO

-- create the user-defined function
CREATE FUNCTION my_business_logic(
@in_dept INTEGER
)
RETURNS XML
AS
BEGIN
DECLARE @x XML
-- do some business logic that produces an XML document
RETURN @x
END
GO

-- now call it, using dept 10
SELECT dbo.my_business_logic(10)
GO