XQuery

  • based on the @SPName (name of the StoredProcedure ) I'm trying to execute SQL query read from the XML document dynamically.. But I'm getting only NULL as a result..

    SET @Qry = @Qry + 'SELECT @var = ParamXML.value(''/ROOT[1]/TestCase[' + @TestCaseID + ']/Query[1]/@Expected'',''VARCHAR(MAX)'') '

    + 'FROM dbo.SPParamXML '

    + 'WHERE SPName = @SPName '

    EXEC sp_executesql @Qry, N'@var AS VARCHAR(MAX) OUT,

    @SPName AS VARCHAR(50)', @var OUT, @SPName

    is there any way to execute this scenario dynamically???

  • Why do you want to do this dynamically?

    Have you tried something like this?

    SELECT @var = ParamXML.value('/ROOT[1]/TestCase[position()=sql:variable("@TestCaseID")][1]/Query[1]/@Expected','VARCHAR(MAX)')

    FROM dbo.SPParamXML

    WHERE SPName = @SPName

    ____________________________________________________

    Deja View - The strange feeling that somewhere, sometime you've optimised this query before

    How to get the best help on a forum

    http://www.sqlservercentral.com/articles/Best+Practices/61537

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply