2

我正在尝试将一个过程转换为在 SQL Azure 中使用。我首先收到一条错误消息,OPENXML说 SQL Azure 不支持它,然后我发现它可以替换为nodes.

但我不确定如何转换WITH (Id BIGINT '.')零件。我知道WITH创建一个子查询,但'.'这里在做什么?

CREATE Procedure [dbo].[DocsR]
    @ids    xml     -- <Ids><Id>1</Id><Id>2</Id></Ids>
AS
BEGIN
    SET NOCOUNT ON;

    DECLARE @IdsXml xml 
    exec sp_xml_preparedocument @IdsXml OUTPUT, @Ids

    SELECT
        DoctId,
        DocNm
    FROM
        Docs
    WHERE
        --DocId IN (SELECT Id FROM OPENXML(@IdsXml, '/Ids/Id', 2) WITH (Id BIGINT '.'))
          DocId IN (SELECT Id FROM @IdsXml.nodes('/Ids/Id') WITH (Id BIGINT '.'))
END
GO

错误:

Incorrect syntax near the keyword 'with'. If this statement is a common 
table expression, an xmlnamespaces clause or a change tracking context clause, 
the previous statement must be terminated with a semicolon.
4

1 回答 1

1

尝试以下操作:

  SELECT
        DoctId,
        DocNm
    FROM
        Docs
    WHERE
          DocId IN (SELECT Id = node.value('.', 'INT') 
                      FROM @IdsXml.nodes('/Ids/Id') AS R(node))
于 2012-10-08T21:52:51.713 回答