I don't know if I could do this but I need to try and figure out a way. I have an object that searches an LDAP directory, the problem is that the return value from this LDAP object is XML. I need to be able to parse this XML in a sp to send to another sp which will email the information to specific people. I have tried this code but if I try to print @name from an exec nothing prints out.

Create PROC sp_EMS_Calls

@server varchar(50) = 'midcocm1',
@port int = 8404,
@AttrName varchar(50) = '"givenname,sn","Name","%2, %1",20',
@AuthName varchar(50)= 'cn=Web,o=cisco.com',
@AuthPasswd varchar(50) = 'web',
@ext as varchar(10),
@duration as varchar(10),

--Constants for the LDAP settings to get to the directory server
--Constant for to create the Name Attribute of the Object
@name varchar(1000)OUTPUT

/*Stored Procedure setups on the email to be sent to sp_SMTPMail that accepts addresses
and a body to be emailed out. The sp has to create an object of the LDAPSearch which
will pull the name that matches the extension that called 911.


SET nocount ON
DECLARE @oLDAP int --Object Reference
DECLARE @XML int --Object Reference
DECLARE @return_XML varchar(1000)
--DECLARE @SearchString varchar(50)

--Declare object code for execution
DECLARE @resultcode int
DECLARE @code int

--SELECT @SearchString =

EXEC @resultcode = sp_OACreate 'LDAPSEARCH.LDAPSearchList', @oLDAP OUT

If @resultcode = 0
--Set Server Properties for the LDAP
EXEC @resultcode=sp_OASetProperty @oLDAP, 'Server',@server
EXEC @resultcode=sp_OASetProperty @oLDAP, 'Port',@port
EXEC @resultcode=sp_OASetProperty @oLDAP, 'AuthName',@AuthName
EXEC @resultcode=sp_OASetProperty @oLDAP, 'AuthPasswd',@AuthPasswd

--Create Tags For the XML
EXEC @resultcode=sp_OAMethod @oLDAP, 'AddReturnAttr',@AttrName
--Set what kind of search will be performed
EXEC @resultcode=sp_OAMethod @oLDAP, 'SearchByPhoneNumber',@ext
EXEC @resultcode=sp_OAMethod @oLDAP, 'XMLOutput(1,32)', @return_XML OUT

EXEC @code = sp_OACreate 'msxml2.DOMDocument', @XML OUT

IF @code = 0
EXEC @code=sp_OAMethod @XML, 'loadXML', @return_XML
EXEC @code=sp_OAMethod @XML, 'selectSingleNode("//CiscoIPPhoneDirectory/DirectoryEnter/Name").text', @name

EXEC @code=sp_OADestroy @XML
EXEC @resultcode = sp_OADestroy @oLDAP
Set nocount OFF


DECLARE @lname varchar(50)

EXEC sp_EMS_Calls @ext='0612',@duration='25',@name=@lname OUTPUT

Print @lname


If any body could help me it would be great, Thanks.