SQL语句到CAML查询

时间:2015-08-31 18:50:51

标签: sharepoint sharepoint-2010 caml

我需要帮助将此语句转换为CAML等效语句:

Where startMonth = 1 
And endMonth = 2
And startYear = 2015
And endYear = 2016
And (system1 contains 'x'   or system 2 contains 'x' or system3 contains 'x')
And (status = 'completed' or status = 'Resolved')

1 个答案:

答案 0 :(得分:0)

我自己想出来了,这就是我做的方式(希望能有所帮助)

<Where>
<And>
    <Or>
        <Contains>
            <FieldRef Name='Status' />
            <Value Type='Text'>Completed</Value>
        </Contains> 
        <Contains>
            <FieldRef Name='Status' />
            <Value Type='Text'>Resolved</Value>
        </Contains>
    </Or>
    <And>
        <Or>      
            <Contains>
                <FieldRef Name='System1' />
                <Value Type='Text'>x</Value>
            </Contains>
            <Or>

                <Contains>
                    <FieldRef Name='system2' />
                    <Value Type='Text'>x</Value>
                </Contains> 
                <Contains>
                    <FieldRef Name='system3' />
                    <Value Type='Text'>x</Value>
                </Contains>
            </Or>
        </Or>
        <And>
            <Geq>
                <FieldRef Name='StartYear' />
                <Value Type='Integer'>startYear</Value>
            </Geq>
            <And>
                <Leq>
                   <FieldRef Name='EndYear' />
                   <Value Type='Integer'>endYear</Value>
                </Leq>
                <And>
                     <Geq>
                <FieldRef Name='Start Month' />
                <Value Type='Integer'>startMonth</Value>
                    </Geq>
                    <Geq>
                <FieldRef Name='End Month' />
                <Value   Type='Integer'>endMonth</Value>
                    </Geq>
                </And>
            </And>
        </And>
    </And>
    </And>
</Where>